+
+ my $imgpath = "data/word/org/$row->{id}.jpg";
+ if (my $download = $row->{source} and !-e $imgpath) {
+ require LWP::UserAgent;
+ my $ua = LWP::UserAgent->new;
+ $ua->agent('/');
+ my $status = $ua->mirror($download, $imgpath);
+ $status->is_success or Alert([
+ "Source image not found",
+ "Download from <q>$download</q> failed: ".$status->status_line,
+ ]);
+ }
+
+ my $thumbpath = "data/word/eng/$row->{form}.jpg";
+ if (-e $imgpath) {
+ my @cmds = @{ $row->{thumb} // [] };
+ unshift @cmds, -gravity => @cmds ? 'northwest' : 'center';
+ unshift @cmds, 'convert';
+ push @cmds, -resize => '300x200^', -extent => '300x200';
+ push @cmds, '-strip', -quality => '60%', -interlace => 'plane';
+ push @cmds, $imgpath, $thumbpath;
+ my $status = system @cmds;
+ $status == 0 or Alert([
+ "Thumbnail image not generated",
+ "Failed to convert source image, error code ".($status >> 8),
+ ], "@cmds");
+ }
+
+ $row = {map {$_ => $row->{$_}} qw(lang cat)} if not $Request;