How to resize *.png picture with auto-adjustment?

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
bensto
Posts: 31
Joined: 2012-07-02T00:32:10-07:00
Authentication code: 13

How to resize *.png picture with auto-adjustment?

Post by bensto »

Assume I have an original *.png picture with an unknown (big) width and height.

Now I want to resize/shrink it to a height of 800pixel.
The width should be automatically adjusted so that the height/width ratio of the original picture is kept.
In other words if for one particular PNG picture the height is shrinked to 62% then the width should be shrinked to 62% as well.

How would such a cmdline command look like?

The original PNG picture file should be replaced by the new one.

Is your suggested command picture format independent? read: Can I apply it to JPG pictures as well?

Ben
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How to resize *.png picture with auto-adjustment?

Post by snibgo »

Code: Select all

convert picture.png -resize x800 picture.png
Instead of ".png", use any format you want.

Note: if picture.png is smaller that 800 pixels high, it will be enlarged to that height. To prevent this, use:

Code: Select all

convert picture.png -resize "x800>" picture.png
This works in Windows. Unix may need a different escaping mechanism for the ">" character.

See:
http://www.imagemagick.org/script/comma ... php#resize
http://www.imagemagick.org/script/comma ... p#geometry
snibgo's IM pages: im.snibgo.com
bensto
Posts: 31
Joined: 2012-07-02T00:32:10-07:00
Authentication code: 13

Re: How to resize *.png picture with auto-adjustment?

Post by bensto »

Thank you.

Regarding JPG one more question:

At which compression level will the conversion take place (by default)?

How do I specify a different compression level for JPG?

Ben
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How to resize *.png picture with auto-adjustment?

Post by snibgo »

Specify the compression you want with "-quality". See http://www.imagemagick.org/script/comma ... hp#quality .

If the input is jpeg, the default output quality is the same as the input. If the input isn't jpeg, the current default quality seems to be 92. (I think it used to be 85. Perhaps it depends on the jpeg library. If you want a specific setting, don't rely on the default remaining unchanged.)

Quality 100 for jpeg is the least lossy, but still lossy.
snibgo's IM pages: im.snibgo.com
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: How to resize *.png picture with auto-adjustment?

Post by glennrp »

snibgo wrote: If the input isn't jpeg, the current default quality seems to be 92. (I think it used to be 85. Perhaps it depends on the jpeg library. If you want a specific setting, don't rely on the default remaining unchanged.)
92 is ImageMagick's default in coders/jpeg.c. Digital cameras typically use 90-95.
Post Reply