Search code examples
imagemagickimagemagick-convert

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:- image extracted from gif


2nd image:2nd image


Final output as merge two images :Final out put

Thank you:)


Solution

  • This is a pretty easy way to do it:

    convert -gravity center background.jpg -blur 5x4  \
        \( yinyang.png -resize 130x78\! \)            \
        -composite result.jpg
    

    enter image description here

    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