i am trying to crop a gif image using the libMagick.so library.
./convert --version
Version: ImageMagick 6.2.8 03/31/08 Q16 file:/usr/share/ImageMagick-6.2.8/doc/index.html
using the following command:
convert img.gif -crop 91x68+6+116 out.gif
the out.gif image gets crop, but not re sized. i get the same image size while all of it is transparent except the 91 pixels starting at 6 pixels from the left point and 68 pixels starting 116 pixels from the top.
how can i make the convert comm开发者_JAVA技巧and crop and leave only the cropped part as the output image. by the way, when my output image is jpg, i get the expected results.
You need to add the -repage
option for GIF files:
convert img.gif -crop 91x68+6+116 -repage 0x0 out.gif
The problem is that GIFs can contain multiple images (of different sizes) when they're animated so cropping just affects one of the images while leaving the overall GIF canvas size untouched. Using 0x0
for the canvas size is an easy shortcut to make ImageMagick figure out how big the image should be:
A given a canvas size of zero such as '0x0' forces it to recalculate the canvas size so the image (at its current offset) will appear completely on that canvas.
精彩评论