Trim Animated Gif To Bounding Box
Posted: 2017-06-15T11:08:27-07:00
For those interested in gif animation modifications, I found this an interesting question and solution. See https://stackoverflow.com/questions/445 ... magemagick
Use https://github.com/ImageMagick/ImageMagick/discussions instead.
https://imagemagick.com/discourse-server/
https://imagemagick.com/discourse-server/viewtopic.php?t=32161
As we migrate to IM7 there will be some pretty streamlined ways to accomplish the same things as in IM6. Often we'll be able to obtain image data and use those specs in the same command without using external variables or intermediate files. The rotating bunny GIF image from your linked discussion can be trimmed using a command like this in IM7 (with Windows CMD syntax)...fmw42 wrote: ↑2017-06-15T11:08:27-07:00For those interested in gif animation modifications, I found this an interesting question and solution. See https://stackoverflow.com/questions/445 ... magemagick
Code: Select all
magick oHBWq.gif -coalesce +repage ( -clone 0--1 -transparent %[pixel:p{0,0}] -flatten -trim ) ^
-crop %[fx:u[-1].w]x%[fx:u[-1].h]+%[fx:u[-1].page.x]+%[fx:u[-1].page.y] +repage -delete -1 newgif.gif
I don't think I have an account there. I suppose I should.
I expect those would be some unusually large GIFs.The only potential issue I have is that you need to clone every frame, which could be memory intensive for large animations (in number of frames and dimensions).
Code: Select all
convert oHBWq.gif -coalesce +repage -background none ( -clone 0--1 -trim -flatten -trim ) ^
-set option:distort:viewport %[fx:u[-1].w]x%[fx:u[-1].h]+%[fx:u[-1].page.x]+%[fx:u[-1].page.y] ^
-distort SRT 0 +repage -delete -1 newgif_IM6.gif