Reputation: 9163
I want to resize a picture to a new size using one parameter: Width.
If the picture is horizontal, the new size will be: width = Width, height = proportional to width.
And if the picture is vertical, the new size will be: height = Width, width = proportional to height.
Any idea how to implement this?
I'm using ImageMagick with MagickNet wrapper.
Upvotes: 0
Views: 1356
Reputation: 25830
From the usage reference at http://www.imagemagick.org/Usage/resize/
convert org.jpg -resize widthxwidth final.jpg
e.g. widthxwidth can be 256x256
The aspect ratio will be kept and the resizing will be done within the boundary of 256 X 256 pixel square.
Quoted from the page above:
Resize will fit the image into the requested size. It does NOT fill, the requested box size.
Upvotes: 2
Reputation: 546503
I'm not sure exactly what you mean here. You say you just want to define the width, but in the "vertical" case, you set the height to be the width? Anyway, if you want to resize something using just the width, use this pseudo-code:
ratio = width / height
newWidth = <the new width>
newHeight = newWidth / ratio
If you want to resize the longest size to a given value, try this:
ratio = width / height
if ratio > 1 // wider than it is tall
newWidth = <theValue>
newHeight = newWidth / ratio
else // taller than it is wide
newHeight = <theValue>
newWidth = newHeight * ratio
Upvotes: 1