Announcement

#1 2024-08-28 12:45:12

shutterfreak
Member
2024-08-28
2

ImageMagick commands to generate the derivatives by hand?

Hi,

I have problems creating derivatives for scanned photos (9k x 6k resolution) on my hosted environment (Piwigo 14.5.0, PHP 8.2, MySQL 8.0). I believe that the image conversion takes longer than the maximum execution time as set by my hosting provider. As a result, the gallery, and in fact my entire website, are unresponsive.

I know that I can create the derivatives by hand and upload them in the "_data/i/" folder.

However I'm struggling with the proper imagemagick commands to create the derivatives according to the size definitions from piwigo.

It's apparently possible to 'chain' the creation of derivatives from one image by storing the main image in a memory buffer, as explained at https://stackoverflow.com/questions/122 … t#12688856

So probably I could write something along the following lines:

Code:

for f in *.jpg ; do
  filename_base=${f%.jpg}
  convert "$f"                      \
   -quality 75                      \
   -colorspace rgb                  \
   +profile '*'                     \
   -filter Lanczos                  \
   -write mpr:img                   \
   +delete                          \
   mpr:img -strip -set option:distort:viewport "%[fx:min(w,h)]x%[fx:min(w,h)]+%[fx:max((w-h)/2,0)]+%[fx:max((h-w)/2,0)]" -filter point -distort SRT 0 -resize '250x250' -write "${filename_base}-cu-e250.jpg" +delete \
   mpr:img -strip -set option:distort:viewport "%[fx:min(w,h)]x%[fx:min(w,h)]+%[fx:max((w-h)/2,0)]+%[fx:max((h-w)/2,0)]" -filter point -distort SRT 0 -resize '120x120' -write "${filename_base}-sq.jpg" +delete \
   mpr:img -strip -resize '144x144' -write "${filename_base}-th.jpg" +delete \
   mpr:img -strip -resize '792x792' "${filename_base}-me.jpg"
done

The proper image dimension cropping for Piwigo ('sq', 'th' and 'me' derivatives) are only correct for 'sq'.

Last edited by shutterfreak (2024-08-28 12:53:13)

Offline

 

#2 2024-08-29 00:28:27

OHappyDay
Member
2023-02-08
84

Re: ImageMagick commands to generate the derivatives by hand?

Hi,

as far as I understand ImageMagick resizing an image will conserve the aspect ratio except when your command includes the "!" command to ignore the aspect ratio which the produces the named sizes but will also distort the image (see https://legacy.imagemagick.org/Usage/resize/#resize)

Offline

 

Board footer

Powered by FluxBB

github twitter newsletter Donate Piwigo.org © 2002-2024 · Contact