Resize Image with restrictions

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
MisterJpa
Posts: 11
Joined: 2018-07-23T02:32:48-07:00
Authentication code: 1152

Resize Image with restrictions

Post 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
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Resize Image with restrictions

Post 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.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Resize Image with restrictions

Post by fmw42 »

What is your Imagemagick version? Calculations can be done inline with Imagemagick 7.
User avatar
GeeMack
Posts: 718
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: Resize Image with restrictions

Post 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
MisterJpa
Posts: 11
Joined: 2018-07-23T02:32:48-07:00
Authentication code: 1152

Re: Resize Image with restrictions

Post 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
Post Reply