ImageMagick 2 pictures on top of 1 - imagemagick

I'm using ImageMagick command-line options to create an animation out of several frames. I got it to work but I need to composite 2 pictures onto a third one. Is this possible? So far I have this code :
convert pic1.jpg pic2.jpg -geometry +x +y -composite result.png
This line puts pic2 on top of pic1, is it possible to put 2 pictures on pic1 similar to this:
convert pic1.jpg pic2.jpg -geometry +x +y -composite pic3.jpg +x +y -composite result.png
Something like this if you get my logic

Here's how that looks:
magick xc:blue[600x400\!] \
xc:red[100x100\!] -geometry +100+20 -composite \
xc:lime[200x100\!] -geometry +300+200 -composite result.png

Related

ImageMagick: Remove 2 pixels wide lines

How can I remove two pixels wide lines (like the three lines in the image below) without altering the rest of the image, and repage it to its new minimum border ?
What you want to do is extract the alpha channel. Then use morphology close. Then put the result back into the alpha channel, then trim and save the result. In Imagemagick, that would be:
Input:
convert image.png \
\( -clone 0 -alpha extract -morphology open octagon:2 \) \
-alpha off -compose copy_opacity -composite \
-trim +repage \
result.png
Something like this maybe:
convert captcha.png -morphology erode disk:2 -trim +repage result.png

Merge two Imagemagick convert commands

I'm trying to Create a thumbnail from GIF 1st command and then merge another image on top of it 2nd command.
1st command:-
convert -thumbnail 398x398 -auto-orient -quality 85 giphy.gif[0] output.jpg
2nd command:- convert -size 1920x1080 xc:none output.jpg -blur 5x4 -composite out1.png -gravity center -composite outfinal.png
I've tried using like this but didn't work out:
convert -thumbnail 398x398 -auto-orient -quality 85 giphy.gif[0] output.jpg | convert -size 398x398 xc:none output.jpg -blur 5x4 -composite out1.png -gravity center -composite outfinal.png
Image extracted from gif:-
2nd image:
Final output as merge two images :
Thank you:)
This is a pretty easy way to do it:
convert -gravity center background.jpg -blur 5x4 \
\( yinyang.png -resize 130x78\! \) \
-composite result.jpg
I put a spurious -resize 130x78\! in there so you can see where to do extra operations that only affect the little "yin yang" picture in the middle - you can obviously remove it.
Maybe I can explain the logic... the first line of the command deals with the background, the second line deals with the overlay. So, first, load up the background picture and make all the edits you want to it, i.e. blurring. Then start some "aside-processing" in parentheses which loads up the "yin yang" and applies some edits to that exclusively without affecting the background image. Then, when you are happy with the overlay, exit the parentheses and take the result of the "aside-processing" and overlay it on top of the background. It overlays into the centre because I set the gravity beforehand.
Hope that helps.
Added in response to your comment... if you want to do the extraction as well, just do that in the "aside-processing":
convert -gravity center \
giphy.gif[0] -thumbnail 398x398 -auto-orient -blur 5x4 \
\( yin yang -resize 300x100\! \) \
-composite result.jpg

How to use ImageMagick to place a watermark in multiple locations on an image

I am currently using imagemagick through the command line to place a watermark in multiple locations on another image, but the way I am doing it seems like it probably isn't the best way to go about doing it.
Here is how I am doing it:
exec("convert 'originalImage.jpg' 'watermark.jpg' -gravity NorthWest -geometry +3+3 -define compose:args=30,100 -compose dissolve -composite 'finalImage.jpg'");
exec("convert 'finalImage.jpg' 'watermark.jpg' -gravity NorthEast -geometry +3+3 -define compose:args=30,100 -compose dissolve -composite 'finalImage.jpg'");
exec("convert 'finalImage.jpg' 'watermark.jpg' -gravity SouthWest -geometry +3+3 -define compose:args=30,100 -compose dissolve -composite 'finalImage.jpg'");
This is (1) taking originalImage.jpg and adding watermark.jpg to the top-left corner (with a 3px margin from the top left, using 30% opacity), then (2) taking that resulting finalImage.jpg and adding the watermark to the top-right corner, and then (3) taking that finalImage.jpg again and adding the watermark to the bottom-left corner.
So it is recreating the file three times to come up with the final image. Is there a shorthand way to do this same thing without having to save the file three separate times?
Thanks!
Here is another solution using multiple "-draw" options:
"-draw" doesn't have a "dissolve" option so you'd need to prepare the
watermark image ahead of time to have 30% alpha.
convert watermark.jpg -alpha set -channel alpha -fx .30 watermark30.png
convert originalImage.jpg \
-gravity NorthWest -draw "image over 3,3 0,0 watermark30.png" \
-gravity NorthEast -draw "image over 3,3 0,0 watermark30.png" \
-gravity SouthWest -draw "image over 3,3 0,0 watermark30.png" \
finalImage.jpg
You could combine this with Mark's good recommendation to use the MPR format instead of watermark30.png. I did a couple of "-draw" versus "-composite" timing tests, and it appears that Mark's method is somewhat faster.
I hope you don't mind my editing your post - delete it if you wish - but here is how a single command might look that does the same all in one go:
convert watermark.jpg -alpha set -channel alpha -fx .30 -write MPR:wm30 +delete original.jpg \
-gravity NorthWest -draw "image over 3,3 0,0 'MPR:wm30'" \
-gravity NorthEast -draw "image over 3,3 0,0 'MPR:wm30'" \
-gravity SouthWest -draw "image over 3,3 0,0 'MPR:wm30'" \
finalImage.jpg
Not at a computer, so untested, but this should be close:
convert originalImage.jpg \( watermark.jpg -write MPR:wm \) \
-define compose:args=30,100 -compose dissolve \
-gravity NorthWest -geometry +3+3 -composite \
MPR:wm -gravity NorthEast -geometry +3+3 -composite \
MPR:wm -gravity SouthWest -geometry +3+3 -composite finalImage.jpg
MPR is a RAM-based "Magick Persistent Register" which I use to avoid needing to keep re-reading the watermark.jpg.
The compose arguments persist until changed, so I don't repeat them. It may not be necessary to repeat the second and third -geometry.

ImageMagick Create Image with background and paste 2 images which are resized

I create an Image with necessary size and background
convert -size 1000x750 xc:'#f4f5f6' /test.jpg 2>&1
I need to put other resized image to this new image and then one more for shadows
How to make it in one command?
The operators -geometry & -composite will handle this.
For example...
convert -size 500x375 xc:'#f4f5f6' \
rose: -geometry +100+100 -composite \
\( rose: -negate \) -geometry +400+200 -composite \
out.png

add image to transparent section

I have an image with a couple of transparent boxes. I need to insert some specific images in to the transparent boxes. I tried several convert commands but couldn't end up with a solution.
I am using Windows 10 and imagemagick is working on my CLI with no issues. Hope someone can point me into the right direction.
Let's say this 500x400 image is your starting image and it has transparent holes in it at 10,10 and 250,250.
Now, let's say you have two Mr Beans, bean1.jpg and bean2.jpg like this:
Let's lay it out on a red background so you can see what is going on. We'll resize bean1.jpg and place him in the area of the top-left transparent hole, then we'll set up bean2.jpg for the bottom-right transparent hole:
convert -size 500x400 xc:red \
\( bean1.jpg -resize 101x101! -geometry +10+10 \) -composite \
\( bean2.jpg -resize 131x131! -geometry +250+250 \) -composite \
result.png
Now let's do that again, but this time, overlay the original image so the Beans peek through it:
convert -size 500x400 xc:red \
\( bean1.jpg -resize 101x101! -geometry +10+10 \) -composite \
\( bean2.jpg -resize 131x131! -geometry +250+250 \) -composite \
image.png -composite result.png
On Windows, you have to change the backslashes into carets, so \( becomes ^( and \) becomes ^).

Resources