cropImage bug when using PNG file

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
gan068

cropImage bug when using PNG file

Post by gan068 »

Version:ImageMagick-6.4.5-Q16

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
thx for ImageMagick team.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: cropImage bug when using PNG file

Post by magick »

Perhaps your PNG has a virtual canvas to start with. If so use
  • convert 823185.png +repage -gravity Center -crop 90x90+0+0 +repage tmp_1.jpg
Try this:
  • convert logo: -resize 90x90! 823185.png
    convert 823185.png -gravity Center -crop 90x90+0+0 +repage tmp_1.jpg
    identify tmp_1.jpg
Notice it returns the expected size of 90x90:
  • tmp_1.jpg JPEG 90x90 90x90+0+0 8-bit DirectClass 2.35kb
gan068

Re: cropImage bug when using PNG file

Post by gan068 »

I know it work perfectly when using this command
  • convert 823185.png +repage -gravity Center -crop 90x90 +repage tmp_1.jpg
but my PNG souce size maybe over 3000x2000 or smaller then 100x100,
I can't sure WidthxHeight+0+0 will get right or wrong result.
when using this command
  • convert 823185.png +repage -gravity Center -crop 1600x1600 +repage tmp_1.jpg
the pic will splited by file name tmp_1-0.jpg~tmp_1-n.jpg etc.
So I use the same syntax WidthxHeight+0+0 .
is it not a bug when any png size use -crop WidthxHeight+0+0?


this is my solution,change png to jpg then crop it
  • convert 823185.png -resize 90x90 823185.jpg
    convert 823185.jpg -gravity Center -crop 90x90+0+0 +repage tmp_1.jpg
    del 823185.jpg
    identify tmp_1.jpg
thx a lot for reply....
magick wrote:Perhaps your PNG has a virtual canvas to start with. If so use
  • convert 823185.png +repage -gravity Center -crop 90x90+0+0 +repage tmp_1.jpg
Try this:
  • convert logo: -resize 90x90! 823185.png
    convert 823185.png -gravity Center -crop 90x90+0+0 +repage tmp_1.jpg
    identify tmp_1.jpg
Notice it returns the expected size of 90x90:
  • tmp_1.jpg JPEG 90x90 90x90+0+0 8-bit DirectClass 2.35kb
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: cropImage bug when using PNG file

Post by anthony »

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.

Code: Select all

convert .....options generating a large PNG image.....\
               +repage -write large_image.png \
               -thumbnail 90x90\^  -gravity center -extent 90x90 \
               thumbnail_image.gif
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.

See IM Examples, Thumbnails, Cut Image to fit
http://www.imagemagick.org/Usage/thumbnails/#cut
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
gan068

Re: cropImage bug when using PNG file

Post by gan068 »

this is on document
http://www.imagemagick.org/Usage/resize/dragon.gif
http://www.imagemagick.org/Usage/resize ... dragon.gif

Code: Select all

convert dragon.gif      -resize 64x64^ \
          -gravity center -extent 64x64  fill_crop_dragon.gif


3 source image
http://test.walkone.com.tw/im/hero.jpg
http://test.walkone.com.tw/im/hero.png
http://test.walkone.com.tw/im/823185.png

6 result
http://test.walkone.com.tw/im/result/tmp_1.jpg
http://test.walkone.com.tw/im/result/tmp_2.jpg
http://test.walkone.com.tw/im/result/tmp_3.jpg
http://test.walkone.com.tw/im/result/tmp_4.jpg
http://test.walkone.com.tw/im/result/tmp_5.jpg
http://test.walkone.com.tw/im/result/tmp_6.jpg

these result are wrong
tmp_1.jpg using document syntax,no cropped only extent
tmp_2.jpg using document syntax,no cropped only extent
tmp_3.jpg using document syntax,no cropped only extent
tmp_4.jpg cropped,but 90x90 cropped to 75x90

these result are right!
tmp_3.jpg 90x90 to 90x90
tmp_5.jpg 90x90 to 90x90
tmp_6.jpg 3072x2048 resized and gravity center 90x90 to a square,no extented

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
PS.135x135 is using 3072x2048:?x90 to computed.
because Jmagick only has method cropImage(java.awt.Rectangle),
the method get the wrong result,
So I'm try to using console command ,
but also get wrong result.
thx a lot for all reply...

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.

Code: Select all

convert .....options generating a large PNG image.....\
               +repage -write large_image.png \
               -thumbnail 90x90\^  -gravity center -extent 90x90 \
               thumbnail_image.gif
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.

See IM Examples, Thumbnails, Cut Image to fit
http://www.imagemagick.org/Usage/thumbnails/#cut
Post Reply