Pure geometry calculations without an actual image

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
hakunin
Posts: 13
Joined: 2013-05-15T12:05:55-07:00
Authentication code: 6789

Pure geometry calculations without an actual image

Post by hakunin »

Is there a way to supply original width/height (not an image, just 2 numbers) to convert or identify command, and receive a resulting width/height based on a geometry, as if an actual image was resized? For example: I would supply 1000,600 (w/h) and geometry '600x600>' and I should get 600,360 on output. If I supply 500,400 with the same geometry, I would get 500,400 on output (since I used ">", which does shrink-only).

In my imagination it would look something like this:

Code: Select all

$ identify -calc -width 1000 -height 600 -geometry 600x600> -format "%wx%h"
600x360
This is useful for me because the images are uploaded to S3, and I don't want to download them in order to find out the final sizes, or having to store those sizes in the database for every thumbnail. I also wouldn't want to have to reimplement all the geometry logic in my programming language of choice, if I could simply call imagemagick to do the native calculation.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Pure geometry calculations without an actual image

Post by fmw42 »

-geometry doing resize is a special case and should be avoided in general. You should use -resize or -thumbnail. see http://www.imagemagick.org/Usage/resize/#geometry

Code: Select all

convert -size 1000x600 xc: -resize  "600x600>" -format "%wx%h" info:
600x360
Post Reply