My PNG file pixel:90x90
using cropImage(90x90)
result output jpg format and pixel is change to 75x90
the right result should be 90x90 jpg format.
Code: Select all
convert 823185.png -gravity Center -crop 90x90+0+0 +repage tmp_1.jpg
Code: Select all
convert 823185.png -gravity Center -crop 90x90+0+0 +repage tmp_1.jpg
magick wrote:Perhaps your PNG has a virtual canvas to start with. If so use
Try this:
- convert 823185.png +repage -gravity Center -crop 90x90+0+0 +repage tmp_1.jpg
Notice it returns the expected size of 90x90:
- convert logo: -resize 90x90! 823185.png
convert 823185.png -gravity Center -crop 90x90+0+0 +repage tmp_1.jpg
identify tmp_1.jpg
- tmp_1.jpg JPEG 90x90 90x90+0+0 8-bit DirectClass 2.35kb
Code: Select all
convert .....options generating a large PNG image.....\
+repage -write large_image.png \
-thumbnail 90x90\^ -gravity center -extent 90x90 \
thumbnail_image.gif
Code: Select all
convert dragon.gif -resize 64x64^ \
-gravity center -extent 64x64 fill_crop_dragon.gif
Code: Select all
convert hero.jpg -resize 90x90^ -gravity center -extent 90x90 result\tmp_1.jpg
identify result\tmp_1.jpg
convert hero.png -resize 90x90^ -gravity center -extent 90x90 result\tmp_2.jpg
identify result\tmp_2.jpg
convert 823185.png -resize 90x90^ -gravity center -extent 90x90 result\tmp_3.jpg
identify result\tmp_3.jpg
convert 823185.png -gravity center -crop 90x90+0+0 result\tmp_4.jpg
identify result\tmp_4.jpg
convert 823185.png -resize 90x90 result\823185.jpg
convert result\823185.jpg -gravity Center -crop 90x90+0+0 result\tmp_5.jpg
del result\823185.jpg
identify result\tmp_5.jpg
convert hero.png -resize 135x135 -gravity Center -crop 90x90+0+0 result\tmp_6.jpg
identify result\tmp_6.jpg
anthony wrote:the virtual canvas size and offset is simple meta-data. adding +repage just resets this to the actual image.
It is fast and simple, as it does not effect the image data in any way. You can apply it after reading the PNG, or before writing the PNG image.
I don't see why you would have a problem with it?
Of course if you have the PNG image in memory from some other process you can -write that image, then continue your processing to generate the thumbnail in the same command.The '^' flag is a new resize flag that minimally resizes images so that 90x90 box is contains WITHIN the file image (one end is 90, the other is larger). the extent then crops off the excess.Code: Select all
convert .....options generating a large PNG image.....\ +repage -write large_image.png \ -thumbnail 90x90\^ -gravity center -extent 90x90 \ thumbnail_image.gif
See IM Examples, Thumbnails, Cut Image to fit
http://www.imagemagick.org/Usage/thumbnails/#cut