ifad / colore

COmmon LOcal REpository
MIT License
0 stars 3 forks source link

Fix ImageMagick command for v7 option handling #254

Closed tagliala closed 1 month ago

tagliala commented 1 month ago

Options specified before the input image can be interpreted as options to generate an image.

Example:

convert -size 300x200 xc:lightblue image.png

The -size and xc:lightblue options create a new image, and image.png is considered the output file.

By moving the options after the input image, we ensure that the input file is interpreted correctly and only the output is modified according to the specified options.

This will also add compatibility to ImageMagick v7

tagliala commented 1 month ago

Tested locally with ImageMagick v7 and v6

md5 checksums are the same:

$ convert --version
Version: ImageMagick 6.9.11-60 Q16 x86_64 2021-01-25 https://imagemagick.org
Copyright: (C) 1999-2021 ImageMagick Studio LLC
License: https://imagemagick.org/script/license.php
Features: Cipher DPC Modules OpenMP(3.1) 
Delegates (built-in): bzlib cairo djvu fftw fontconfig freetype gslib gvc heic jbig jng jp2 jpeg lcms ltdl lzma openexr pangocairo png ps raqm raw rsvg tiff webp wmf x xml zlib

$ convert -depth 8 -density 300 -background white -alpha off png-demo.png png-demo.tiff && md5sum png-demo.tiff
9b7a1a8a173c5519bb6aa7f6cfeb9481  png-demo.tiff

$ convert png-demo.png -depth 8 -density 300 -background white -alpha off png-demo.tiff && md5sum png-demo.tiff
9b7a1a8a173c5519bb6aa7f6cfeb9481  png-demo.tiff
$ magick --version
Version: ImageMagick 7.1.1-38 Q16-HDRI x86_64 22398 https://imagemagick.org
Copyright: (C) 1999 ImageMagick Studio LLC
License: https://imagemagick.org/script/license.php
Features: Cipher DPC HDRI Modules OpenMP(5.0) 
Delegates (built-in): bzlib fontconfig freetype gslib heic jng jp2 jpeg jxl lcms lqr ltdl lzma openexr png ps raw tiff webp xml zlib zstd
Compiler: gcc (4.2)

$ magick png-demo.png -depth 8 -density 300 -background white -alpha off png-demo.tiff && md5sum png-demo.tiff
2ab0d2a5e344a24be573d368c5f15e0d  png-demo.tiff

$ magick -depth 8 -density 300 -background white -alpha off png-demo.tiff && md5sum png-demo.png png-demo.tiff
magick: no images found for operation `-alpha' at CLI arg 7 @ error/operation.c/CLIOption/5481.