Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top