resize ! not working properly

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
troyd1
Posts: 73
Joined: 2007-07-29T17:13:19-07:00

resize ! not working properly

Post by troyd1 »

I have 7.0.1 q16 dynamic - window XP.

I have been trying the resize with the ! option and in some cases, it will put whitespace on the top and bottom of the resized image.

If I do:
convert 4.jpg -resize 1650x1275! 4.png

Instead of resizing to fill the page, it appears to enlarge it and then add whitespace to fill the rest. It seems to work for some images. Can someone please explain this?

Here is a link to the image that does not work properly.
http://www.northstardata.net/graphicstemp/4.jpg
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: resize ! not working properly

Post by fmw42 »

what version of IM are you using? type

convert -version

and tell us what you have. IM is not at version 7, but 6.7.0.2 as the latest. IM 7 has forked and is in pre-alpha.


try either quoting or escaping !

convert 4.jpg -resize "1650x1275!" 4.png

convert 4.jpg -resize 1650x1275^! 4.png

for windows users see differences at http://www.imagemagick.org/Usage/windows/
troyd1
Posts: 73
Joined: 2007-07-29T17:13:19-07:00

Re: resize ! not working properly

Post by troyd1 »

C:\temp\TST>convert -version
Version: ImageMagick 6.7.0-0 2011-05-20 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2011 ImageMagick Studio LLC
Features: OpenMP

Sorry, about the version misinformation.

I tried quoting and it makes no difference and I know the resize is being done, just not properly. It works on a lot of images, just not this one and a few others that I have tried.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: resize ! not working properly

Post by fmw42 »

troyd1
Posts: 73
Joined: 2007-07-29T17:13:19-07:00

Re: resize ! not working properly

Post by troyd1 »

Sorry about that. It is back now.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: resize ! not working properly

Post by fmw42 »

the white space is already in your input image. by the way, the EXIF width and height do not match the actual image size (see convert 4.jpg -verbose info:). so that is probably the cause of your problem. you have some display system (perhaps in your camera) that uses the exif size, but the image it exports is actually bigger and has white on top and bottom to fill it out the actual file size.

try viewing it somewhere else

otherwise, you need to extract the exif size using string format into a variable and then crop your image appropriately. see

ww=`convert 4.jpg -format "%[EXIF:ExifImageWidth]" info:`
hh=`convert 4.jpg -format "%[EXIF:ExifImageLength]" info:`
echo "ww=$ww; hh=$hh"
convert 4.jpg -gravity center -crop ${ww}x${hh}+0+0 +repage 4_cropped.jpg

or

convert 4.jpg -gravity center -crop ${ww}x${hh}+0+0 +repage -resize 1650x1275\! 4_resized.jpg


Alternately, just trim the white from your image

convert 4.jpg -fuzz 5% -trim +repage 4_trim.jpg

and

convert 4.jpg -fuzz 5% -trim +repage -resize 1650x1275\! 4_trim_resized.jpg


By the way, for jpg, +repage is not needed, but for other formats such as png, it will be. But it does not harm to leave it in.


The above seems to work fine for me on IM 6.7.0.2 Q16 Mac OSX Tiger (Unix)

For windows users, see difference in syntax at http://www.imagemagick.org/Usage/windows/

For example:


convert 4.jpg -fuzz 5% -trim +repage -resize 1650x1275^! 4_trim_resized.jpg
or
convert 4.jpg -fuzz 5% -trim +repage -resize "1650x1275!" 4_trim_resized.jpg


see
http://www.imagemagick.org/Usage/crop/#crop
http://www.imagemagick.org/Usage/crop/#trim
Post Reply