Resizing images to fit in a bounding box with ImageMagick
A common problem on the web is the need to resize images such that they fit within a bounding box. If someone gives you an image that fits inside the box, the image is left as is, if the image goes outside the box (in either or both directions) the image is scaled so that either the height or width matches the box limit, and the other dimension is within the box.
Turns out this is really easy to do with the ImageMagick mogrify command, you can use a command like the following (which is using a bounding box 600 pixels wide, and 500 pixels high):
This will resize imageName.jpg as needed. Even better, you can operate on an entire directory of images in this same manner:
Turns out this is really easy to do with the ImageMagick mogrify command, you can use a command like the following (which is using a bounding box 600 pixels wide, and 500 pixels high):
mogrify -geometry '600x500>' imageName.jpg
This will resize imageName.jpg as needed. Even better, you can operate on an entire directory of images in this same manner:
mogrify -geometry '600x500>' *.jpg
| Rating: | 100% positive, 2 total Votes |
| Categories: | imagemagick graphics |
| Added: | on May 27, 2007 at 7:24 am |
| Added By: | an anonymous user |

