Page 1 of 1

Resize Image with restrictions

Posted: 2018-08-14T02:00:38-07:00
by MisterJpa
Hello,

I have a customer that request an ImageMagick command that convert an image to a jpeg. He told me :
"We want JPG files with 2000 pixels at least for the smallest side and 3000 pixels at least for the bigger side."

I thought I could do it with something like widthxheight^ (found : http://www.imagemagick.org/script/comma ... p#geometry) if I knew the image orientation first, but unfortunately they want to provide both landscape and portait image to the same command.

Did someone have an idea on how to match the customer need?

Many thanks in advance,
Regards,
MisterJpa

Re: Resize Image with restrictions

Posted: 2018-08-14T08:17:19-07:00
by snibgo
So, you can make all your images 5000 by 5000 pixels and your customer will be happy? Maybe not.

I would do this in three steps:

1. Find the current size.

2. Do some processing to calculate the new size.

3. Resize, or crop, or whatever is wanted, to the new size.

Re: Resize Image with restrictions

Posted: 2018-08-14T09:55:41-07:00
by fmw42
What is your Imagemagick version? Calculations can be done inline with Imagemagick 7.

Re: Resize Image with restrictions

Posted: 2018-08-14T18:06:14-07:00
by GeeMack
MisterJpa wrote: 2018-08-14T02:00:38-07:00Did someone have an idea on how to match the customer need?
Using ImageMagick 6 it can be done with a command like this...

Code: Select all

convert input.jpg \
   -set option:distort:scale "%[fx:max((w>h?3000:2000)/w,(w>h?2000:3000)/h)]" \
   -distort SRT 0 output6.jpg
It can be done with a simpler command if you're using ImageMagick 7...

Code: Select all

magick input.jpg -resize "%[fx:w>h?3000:2000]x%[fx:w>h?2000:3000]^" output7.jpg

Re: Resize Image with restrictions

Posted: 2018-08-15T11:09:02-07:00
by MisterJpa
Hello,

I'm using ImageMagick 7.
I will try this on Friday at work and keep you updated :)

Many many thanks !
Regards,
MisterJpa