From: Mischa POSLAWSKY Date: Wed, 5 Jan 2022 00:04:53 +0000 (+0100) Subject: word/edit: crop coordinates separate from convert parameters X-Git-Tag: v1.13~46 X-Git-Url: http://git.shiar.nl/sheet.git/commitdiff_plain/492daa38d18c5b1eb173f4a4ccd4ae43968c3b3d word/edit: crop coordinates separate from convert parameters Move -area value into a distinct image column crop32: UPDATE word SET image = jsonb_insert( image #- '{convert,0}' #- '{convert,0}', '{crop32}', image->'convert'->1 ) WHERE image->'convert'->>0 = '-area'; UPDATE word SET image = jsonb_insert( image #- '{convert,2}' #- '{convert,2}', '{crop32}', image->'convert'->3 ) WHERE image->'convert'->>2 = '-area' AND image->'convert'->>0 = '-gravity'; Remaining usage may be influenced by preceding options and need manual inspection. --- diff --git a/Shiar_Sheet/ImagePrep.pm b/Shiar_Sheet/ImagePrep.pm index 2bd4cd9..04a4270 100644 --- a/Shiar_Sheet/ImagePrep.pm +++ b/Shiar_Sheet/ImagePrep.pm @@ -31,14 +31,15 @@ sub dimensions ($imgpath) { return split /\s/, $xy, 3; } -sub generate ($imgpath, $thumbpath, $cmds) { +sub generate ($imgpath, $thumbpath, $opt) { if (not -e $$imgpath) { return !-e $thumbpath || unlink $thumbpath; } - $cmds //= []; - $imgpath->convert($thumbpath, $cmds, '300x200') and # low-res cover + my @cmds = @{$opt->{convert} // []}; + unshift @cmds, -area => $_ for $opt->{crop32} || (); + $imgpath->convert($thumbpath, \@cmds, '300x200') and # low-res cover $imgpath->convert($thumbpath =~ s/\.jpg$/.webp/r, - [@{$cmds}, -quality => 40], '600x400' # higher dpi tradeoff + [@cmds, -quality => 40], '600x400' # higher dpi tradeoff ); } diff --git a/word/edit.plp b/word/edit.plp index 426fb5c..9af73cd 100644 --- a/word/edit.plp +++ b/word/edit.plp @@ -111,6 +111,7 @@ my %wordcol = ( convert => {-label => 'Convert options', -json => 'image', -multiple => 1, -src => sub { return "data/word/32/$_[0]->{id}.jpg"; }}, + crop32 => {-label => 'Crop 3:2', -json => 'image'}, story => {-label => 'Story', type => 'textarea', hidden => 'hidden'}, ); @@ -218,7 +219,7 @@ elsif (defined $post{form}) {{ $reimage++ if $fields{rethumb}; # force refresh if ($reimage) { eval { - $image->generate($wordcol{convert}->{-src}->($row), $imagecol->{convert}); + $image->generate($wordcol{convert}->{-src}->($row), $imagecol); } or do { my ($warn, @details) = ref $@ ? @{$@} : $@; Alert([ "Thumbnail image not generated", $warn ], @details);