Convert considering image DPI

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

Convert considering image DPI

Post by MisterJpa »

Hello,

I have written (thanks to your forum) a command line that convert an image to a jpeg file in 2000.3000px or in 3000.2000px depending on the orientation of the image.
Here is the command (where filename will automatically be replaced by the name of the master) :
magick ${filename} -resize "[fx:w>h?3000:2000]x%[fx:w>h?2000:3000]" rendition.3000.3000.jpg
The customer does now submit this new constraint for my 3000x3000 image generation :

- if the master file (TIF, JPG or PNG) dimension is smaller than 3000 for the bigger side and the resolution = 300 dpi:=>then the "JPG HD rendition" must keep the same dimension as the master file
- if the master file (TIF, JPG or PNG) resolution is over 72 dpi and under 300 dpi:=> the "JPG HD rendition" must keep the same dimension and resolution as the master file
- if the master file (TIF, JPG or PNG) resolution is under 72 dpi:=> the "JPG HD rendition" must keep the same dimension and resolution as the master file

Is there fonctions to check image dpi ?
Do you think it's possible to match those requirement with one magick command ?

I'm currently using ImageMagick 7.0.8-7 on a linux server.

Many thanks by advance,
Regards,
MisterJpa
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Convert considering image DPI

Post by snibgo »

Resolution is available in expressions: %x and %y. See https://www.imagemagick.org/script/escape.php

I expect you can do that in a single magick command. For example if some condition means no resizing should be done, then you can clone the image, resize the clone, then delete whichever image you don't need.

But your conditions seem rather complex. I would probably do this in a shell script.
snibgo's IM pages: im.snibgo.com
Post Reply