Reputation: 12024
Currently I have to do:
convert src.jpg -resize 600 -quality 70 -colorspace sRGB scaled_images/one.jpg
composite -dissolve 25% -gravity center overlay_image1.png scaled_images/one.jpg scaled_images/one.jpg
composite -dissolve 60% -gravity southeast overlay_image2.png scaled_images/one.jpg scaled_images/one.jpg
composite -dissolve 85% -gravity north overlay_image3.png scaled_images/one.jpg scaled_images/one.jpg
Due to multiple cycles of compression/decompression final image quality will suffer.
How can I combine all of above in one command?
I am using imagemagick version 7.0.8-40.
Upvotes: 2
Views: 662
Reputation: 5385
First, when using ImageMagick version 7 you should be using the command "magick" instead of "convert". That said, here is an example that should do what you're trying to accomplish in a single command...
magick src.jpg -resize 600 -compose dissolve \
-define compose:args=25 -gravity center overlay1.png -composite \
-define compose:args=60 -gravity southeast overlay2.png -composite \
-define compose:args=85 -gravity north overlay3.png -composite \
-quality 70 one.jpg
That starts by reading the input image, resizing it to 600 pixels, and setting the compose method to "dissolve". Then it sets the dissolve amount to 25%, sets the gravity to "center", and composites the first overlay image onto the source. It continues by setting the required dissolve amount and gravity for each successive overlay and composites them onto the results of each previous operation.
End by setting the compression quality for the output JPG and writing the output file. The result will be the source image with multiple overlays, each with differing transparencies and locations, and all done within a single command to avoid degradation through the process.
If you're running on Windows you'll need to change those continued line backslashes "\" to carets "^".
Also note, if you ever do have to save and re-read intermediate files you should not save them in JPG format because there will be a loss of quality with each iteration.
Upvotes: 4