There's plenty of information about cropping images, but attempting to crop (or trim) animations produces strange results. Sometimes they flicker, or come with extra frames, or some frames crop correctly and others become offset. How do I prevent all this from happening?
To crop an image using ImageMagick, you need to specify the X and Y coordinates of the top corner of the crop rectangle and the width and height of the crop rectangle. Use the mogrify command if you want the images to be replaced in-place or use the convert command otherwise to make a copy.
convert input.gif -coalesce -repage 0x0 -crop WxH+X+Y +repage output.gif
-coalesce
rebuilds the full frames.-repage 0x0
.+repage
after the crop will do this.Even with the coalesce and repage, I could not get ImageMagick to crop and resize animated gifs very well.
I found a program called Gifsicle and it works great for manipulating animated gifs.
gifsicle --crop 0,0-100,100 --output out.gif in.gif
It can also do all sorts of other operations. Check it out!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With