Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImageMagick - Resize to max width

I want to resize an image to a max width. So I don't care about the height of the image, but I just want to always resize it to a specific width.

I'm certain I've done this before I just can't remember how I did it now.

like image 975
Brett Avatar asked Dec 05 '11 21:12

Brett


3 Answers

Seems this is the way it is done, noting that width is the first parameter.

convert -resize '100' image.png

For anyone else wondering about height, then you would do this:

convert -resize 'x100' image.png

Source: http://www.imagemagick.org/script/command-line-processing.php

Edit (Nov 2014): Note that in the latest versions of ImageMagick you can no longer use quotes around the values as per Kevin Labécot's comment.

like image 138
Brett Avatar answered Nov 02 '22 00:11

Brett


Your question is ambiguous. Your titles asks to resize an image to a max width, but then you seem to say you want to resize the image to a specific width.

If you want to resize something to a max width of 600px (ie, any image with a width of less than 600px will be unaffected), use:

convert original_image.jpg -resize 600x\> result_image.jpg

Or, to directly modify the original image:

mogrify  -resize 600x\> original_image.jpg

If you'd like max height rather than max width:

convert original_image.jpg -resize x600\> result_image.jpg
like image 5
Sofox Avatar answered Nov 02 '22 01:11

Sofox


Are you just chasing the math to work out the correct aspect ratio?

$new_width = 400; // config
$image_width = 480; // loaded from image
$image_height = 786; // loaded from image
$new_height = $new_width * ($image_height / $image_width);
echo "$image_width x $image_height becomes $new_width x $new_height";
like image 3
Scuzzy Avatar answered Nov 02 '22 01:11

Scuzzy