Changing Image 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?".
Locked
aamir4774@gmail.com
Posts: 20
Joined: 2019-03-05T22:47:03-07:00
Authentication code: 1152

Changing Image resolution

Post by aamir4774@gmail.com »

Hi Community,

I trying to change the resolution of the image by using -density command and using that I'm able to do so. But when I add the "-strip" attribute to the command, the density command doesn't seem to work. (For e.g. if I specify density as 144 then the resolution gets changed to 72 which is perhaps incorrect). Well the reason for using the -strip is because along with other file formats I have TIFFs to change resolution and I need to remove the tagged metadata with the image.

Here's an example command I tried with 300dpi i/p image:

Code: Select all

magick "IP" -density 0144 -strip "OP"
The above command gives the o/p resolution as 72 which is somewhat incorrect. Is -strip command restricting the conversion or something? Can you please help.

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

Re: Changing Image resolution

Post by fmw42 »

Put the -strip before the -density

aamir4774@gmail.com
Posts: 20
Joined: 2019-03-05T22:47:03-07:00
Authentication code: 1152

Re: Changing Image resolution

Post by aamir4774@gmail.com »

Yes, that works for the o/p format same as that of input format but for different ones it falls back to 72

snibgo
Posts: 13034
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Changing Image resolution

Post by snibgo »

What version of IM, on what platform?

What are your input and output formats?

You might also include "-units".
snibgo's IM pages: im.snibgo.com

aamir4774@gmail.com
Posts: 20
Joined: 2019-03-05T22:47:03-07:00
Authentication code: 1152

Re: Changing Image resolution

Post by aamir4774@gmail.com »

I'm on Windows 7.0.8-62 Q16 x64 version. The input will mostly be jpegs and outputs can differ like jpegs, png, tiff, bmp or psd's.
To my extent -units should be used when resolution is in dots per centimeter format I believe.

snibgo
Posts: 13034
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Changing Image resolution

Post by snibgo »

It seems to work fine for me, v7.0.8-64 on Windows 8.1:

Code: Select all

%IMG7%magick rose: -density 300 -units Pixelsperinch x.jpg
%IMG7%magick rose: -density 300 -units Pixelsperinch x.png
%IMG7%magick rose: -density 300 -units Pixelsperinch x.tiff
%IMG7%magick rose: -density 300 -units Pixelsperinch x.bmp
%IMG7%magick rose: -density 300 -units Pixelsperinch x.psd

%IMG7%magick identify -format "%%f %%x %%y %%U\n" x.jpg
%IMG7%magick identify -format "%%f %%x %%y %%U\n" x.png
%IMG7%magick identify -format "%%f %%x %%y %%U\n" x.tiff
%IMG7%magick identify -format "%%f %%x %%y %%U\n" x.bmp
%IMG7%magick identify -format "%%f %%x %%y %%U\n" x.psd

Code: Select all

x.jpg 300 300 PixelsPerInch
x.png 118.11 118.11 PixelsPerCentimeter
x.tiff 300 300 PixelsPerInch
x.bmp 118.11 118.11 PixelsPerCentimeter
x.psd 300 300 PixelsPerInch
x.psd 300 300 PixelsPerInch
If it goes wrong for you, please show an example.
snibgo's IM pages: im.snibgo.com

aamir4774@gmail.com
Posts: 20
Joined: 2019-03-05T22:47:03-07:00
Authentication code: 1152

Re: Changing Image resolution

Post by aamir4774@gmail.com »

Yes it works, but my query here is the density command along with -strip doesn't generate the op image with the specified dpi.

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

Re: Changing Image resolution

Post by fmw42 »

For what output type? If PNG, it is automatically converted to the equivalent dots per centimeter, since PNG does not support dots per inch.

Locked