- 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");
+ if ($imgpath) {
+ if (-e $imgpath) {
+ my @cmds = @{ $row->{thumb} // [] };
+ @cmds = (
+ 'convert',
+ -delete => '1--1', -background => 'white',
+ -gravity => @cmds ? 'northwest' : 'center',
+ @cmds,
+ -resize => '300x200^', -extent => '300x200',
+ '-strip', -quality => '60%', -interlace => 'plane',
+ $imgpath => $thumbpath
+ );
+ my $status = system @cmds;
+ $status == 0 or Alert([
+ "Thumbnail image not generated",
+ "Failed to convert source image, error code ".($status >> 8),
+ ], "@cmds");
+ }
+ else {
+ unlink $thumbpath;
+ }