Search code examples
animationimagemagicktransparencygif

How to use convert -crop to add more background to animated gif/enlarge image?


I'm trying to crop an animated gif usind convert -crop. In some cases it's necessary to add more background to the image to fit. With other image formats it's done with

convert original.gif -rotate 0 -crop 1519x759-237-61\! -background white -flatten edited.gif

For gifs I tried

convert original.gif -coalesce -rotate 0 -crop 1519x759-237-61\! +repage edited.gif

convert is clipping/trimming the background and just the "subject" of the image is shown.

Example is here: https://i.sstatic.net/vpbTD.jpg

Result is here: https://i.sstatic.net/yvtJI.jpg

Expected Result is https://i.sstatic.net/lQiYu.jpg

I added the red border to show how big the image is. Someone with a great solution? :)

Jan


Solution

  • To do what you want in Imagemagick, you should be using -extent rather than -crop in order to extend the size of the output.

    Try this. Adjust the size and offset and background color as desired.

    convert original.gif -coalesce -rotate 0 +repage -background white -extent 1519x759-237-61! -bordercolor red -border 3 result.gif
    


    enter image description here

    I have added a red border around the image.