Hello,
I need to convert an image from the command line to a fixed sized, but maintain the aspect ratio of the image content. This gets me close:
convert -resize 256x256 infile.jpg outfile.jpg
The problem being that I end up with one dimension that is less than 256 pixels. What I need is to fill in that space with black or transparent pixels above and below the image content to bring that dimension up to 256 pixels.
Any ideas on command line arg combinations to try?
Resize to a fixed geometry but maintain aspect ratio
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Resize to a fixed geometry but maintain aspect ratio
smithmarkl wrote:Hello,
I need to convert an image from the command line to a fixed sized, but maintain the aspect ratio of the image content. This gets me close:
convert -resize 256x256 infile.jpg outfile.jpg
The problem being that I end up with one dimension that is less than 256 pixels. What I need is to fill in that space with black or transparent pixels above and below the image content to bring that dimension up to 256 pixels.
Any ideas on command line arg combinations to try?
see my tidbits page http://www.fmwconcepts.com/imagemagick/ ... ize_square
Re: Resize to a fixed geometry but maintain aspect ratio
That was very helpful. This does the trick:
convert -resize 256x256 infile.jpg -background none -gravity center -extent 256x256 outfile.jpg
convert -resize 256x256 infile.jpg -background none -gravity center -extent 256x256 outfile.jpg
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Resize to a fixed geometry but maintain aspect ratio
Generally this is know and thumbnail padding
http://www.imagemagick.org/Usage/thumbnails/#pad
Also please start reading the image before working on it, or you will have problems in the future.
EG: convert {read options} image {conversion operators} save_image
http://www.imagemagick.org/Usage/thumbnails/#pad
Also please start reading the image before working on it, or you will have problems in the future.
EG: convert {read options} image {conversion operators} save_image
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/