Bumping up resolution ...

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
dbee

Bumping up resolution ...

Post by dbee »

I want change resolution of photos to 300dpi if the resolution is greater than 300dpi. But if the resolution is less than 300dpi, then i just want to leave it ...

Code: Select all

550dpi -> 300dpi
72dpi -> 72dpi
At the moment I'm using ...

Code: Select all

convert pics/* -density 300*300 -thumbnail 850X850 -compress zip -strip albumshopper/*.jpg
Is there a native ImageMagick way to do this ? Is my script above optimal or is there something I'm missing ?

Thanks,
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Bumping up resolution ...

Post by fmw42 »

You need to use some unix or your api. For example:

# find the image resolution
xres=`convert yourimage -format "%[xresolution]" info:`
yres=`convert yourimage -format "%[yresolution]" info:`
# test if greater than 300 and convert
if [ $xres -gt 300 -o $yres -gt 300 ]; then
convert yourimage -density 300 resultimage
fi

see string formats at http://www.imagemagick.org/script/escape.php
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Bumping up resolution ...

Post by anthony »

WARNING:
  • If your image is JPEG, using IM to change resoultion will make the jpeg quality worse due to a read/write cycle with its lossy compression. Better to use jhead or some other program.
  • Photoshop often ignores the JPEG density, if it has its own profile present in the image.
  • Changing a images resolution does not change the image at all, just the size of the pixels when some real world device wants to determine its real world size. That is just changing density smaller, will make an image larger in real world terms, even tough the number of pixels in the image has not changed.
  • To resize the image (in terms of the number of pixels) so the real world size does not change with a resolution change, use -resample instead of -density or -set density. see IM examples Resample - Changing an images resolution
If you are changing density to reduce data size, use -resample
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply