Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resize image with mogrify without keeping aspect ratio

I feel silly for having to ask such a simple question, but I have spent the past hour having absolutely no luck whatsoever finding a solution to this. Everyone seems like they need to do the exact opposite of what I need to do.

My question is simply how do I tell mogrify and/or convert to not keep the aspect ratio when resizing an image? I need the image to be an exact power of 2 for both width and height and the images do not come in a 1:1 ratio which means one side has to stretch.

The closest thing I have to an answer is the -extent flag, but that just extends the canvas. I need the original image to fill the entire thing.

like image 359
ozdrgnaDiies Avatar asked Dec 07 '13 07:12

ozdrgnaDiies


People also ask

How do I resize an image without changing the aspect ratio?

Press-and-hold the Shift key, grab a corner point, and drag inward to resize the selection area. Because you're holding the Shift key as you scale, the aspect ratio (the same ratio as your original photo) remains exactly the same.

How do I resize an image in ImageMagick?

To resize an image to specific dimensions, use the convert command with an input file, the -resize parameter, your preferred dimensions, and an output filename: convert original. png -resize 100x100 new. png.

Why is it important to maintain aspect ratios when resizing an image?

When scaling your image, it's crucial to maintain the ratio of width to height, known as aspect ratio, so it doesn't end up stretched or warped. If you need a specific width and height, you may need a mixture of resizing and cropping to get the desired result.


2 Answers

After another half hour of searching I have stumbled upon the overly simple answer. The following will resize an image with the exact dimensions given:

mogrify input.png -resize 256x256! output.png

If you want to read more about it, I got the answer from this link:

https://superuser.com/questions/212752/how-to-stretch-an-image-in-one-dimension

like image 80
ozdrgnaDiies Avatar answered Oct 12 '22 05:10

ozdrgnaDiies


use "!" in convert -resize, for ex:

convert "from-img"  -resize 800x480! "to-img"
like image 5
chikadance Avatar answered Oct 12 '22 03:10

chikadance