convert image 75 dpi to 300 dpi

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
Post Reply
ratneshsoni
Posts: 38
Joined: 2010-12-14T03:56:10-07:00
Authentication code: 8675308

convert image 75 dpi to 300 dpi

Post by ratneshsoni »

helloo i want to convert 75 dpi image into 300 dpi.
is it possible using IM.
help me in regarding this
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: convert image 75 dpi to 300 dpi

Post by fmw42 »

convert image -density 300 -units pixelsperinch resultimage

see
http://www.imagemagick.org/script/comma ... ptions.php


Depending upon how you want this converted you may need to use -resample. See above
Drarakel
Posts: 547
Joined: 2010-04-07T12:36:59-07:00
Authentication code: 8675308

Re: convert image 75 dpi to 300 dpi

Post by Drarakel »

@Fred: I think you meant "-density"..

But a different order is recommended with current IM versions (so that it works for all images):

Code: Select all

convert -units PixelsPerInch image -density 300 resultimage
The same with resample. If resampling to 300dpi is needed, use this:

Code: Select all

convert -units PixelsPerInch image -resample 300 resultimage
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: convert image 75 dpi to 300 dpi

Post by fmw42 »

Drarakel wrote:@Fred: I think you meant "-density"..

But a different order is recommended with current IM versions (so that it works for all images):

Code: Select all

convert -units PixelsPerInch image -density 300 resultimage
The same with resample. If resampling to 300dpi is needed, use this:

Code: Select all

convert -units PixelsPerInch image -resample 300 resultimage

Yes, typo. My mind is going! :shock: Thanks for correcting.

If you have a pdf input image then -density needs to be before the input image.

Drarakel,

Under what conditions do you need to have -units first other than for vector images? This is new to me. Is it a bug? Has it been reported?

Fred
Drarakel
Posts: 547
Joined: 2010-04-07T12:36:59-07:00
Authentication code: 8675308

Re: convert image 75 dpi to 300 dpi

Post by Drarakel »

fmw42 wrote:Under what conditions do you need to have -units first other than for vector images? This is new to me. Is it a bug?
No, not a bug - a feature. (Or rather: the special behaviour of the feature in "-units" that converts the density value.) But granted, not a well-documented one. I'll try to explain the small obstacles with that..

As you probably know, if the input file has a density value in PixelsPerCentimeter, "-units PixelsPerInch" will change the units value, but also converts the density to the proper value. But setting the density AND unit can be a bit more problematic. Example - if you want to change a 75dpi image to the value 300dpi that way:

Code: Select all

convert rose: -set units PixelsPerInch -density 75 rose1.png
convert rose1.png -density 300 -units PixelsPerInch rose2.jpg
Then you will have a value of 762dpi in the end. (75dpi in the input image is actually stored as 25.92 PixelsPerCentimeter. Or rather pixels per meter, but anyway.. With the second command, you first change it to 300 PixelsPerCentimeter, and then this value will be converted to the respective PixelsPerInch value.) And changing the order to "inputimage -units PixelsPerInch -density 300" doesn't help. As "-units" doesn't behave as a normal operation anymore, but sets only a 'hint' that will be executed later (that's at least my interpretation). You will still first change the value to 300 PixelsPerCentimeter, and only at the very end of the command, this will be converted to 762 PixelsPerInch.
Now, using "-units" before the input file behaves differently:

Code: Select all

convert -units PixelsPerInch rose1.png -density 300 rose2b.jpg
This ensures that the density value will be a PixelsPerInchValue right at the start (75 PixelsPerInch) - after that it will be changed to 300 (PixelsPerInch).

Of course, there are other possibilities for simply changing both the density and unit value in current IM versions - as one can use "-set":

Code: Select all

convert rose1.png -set units PixelsPerInch -density 300 rose2c.jpg
Here, the order doesn't matter. (And for "-density", one could also use "-set density". There's virtually no difference now.)

But: With "-resample", the first recommendation is essential:

Code: Select all

convert -units PixelsPerInch rose1.png -resample 300 rose2d.jpg
It only works that way (for input files that can be PixelsPerInch or PixelsPerCentimeter).
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: convert image 75 dpi to 300 dpi

Post by fmw42 »

Thanks.

Fred
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: convert image 75 dpi to 300 dpi

Post by anthony »

I do know that -density should be just a setting of the image meta-data. I would probably have expected something similar with units, in which case order between the two should not matter. However they both probably should be set after reading the image.

The problem is that density is also a 'input setting'. That is a global setting that is saved so that vector images can use the value when they are 'rasterized'. As such their use is confusing.

That is -density is being dual purposed as both a input setting for images that is created and read in, and as image meta-data modifier operator after images have been read in.

In other words it is more than likely that the two aspects are causing buggy behaviour.


ASIDE: It is for this reason that many options such as -label is strictly a input setting only, while -set label is strictly used as a meta-data attribute changing operator!

For more on this distinction see IM Examples Basics,
Image Meta-data: Attributes, Properties and Artifacts
http://www.imagemagick.org/Usage/basics/#settings

It may be time for the same separation of handling to happen to -density and -unit attributes.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Jimbo
Posts: 23
Joined: 2019-08-26T12:24:48-07:00
Authentication code: 1152

Re: convert image 75 dpi to 300 dpi

Post by Jimbo »

Just an FYI (and possibly a BUG), none of this dpi stuff works with EXR images. Yes, openEXR assures me that it supports dpi.

Have any of you tried changing the dpi of an EXR image? If you've successfully done it. I would love to see that convert call.

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

Re: convert image 75 dpi to 300 dpi

Post by fmw42 »

Drarakel wrote: 2011-03-08T11:57:43-07:00 @Fred: I think you meant "-density"..
Yes, typo. Thanks for catching it. I have corrected my post.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: convert image 75 dpi to 300 dpi

Post by fmw42 »

Jimbo wrote: 2019-08-26T18:41:13-07:00 Just an FYI (and possibly a BUG), none of this dpi stuff works with EXR images. Yes, openEXR assures me that it supports dpi.

Have any of you tried changing the dpi of an EXR image? If you've successfully done it. I would love to see that convert call.

Thanks.
- Jimbo
You can request an enhancement on this the developers forum. But there is no guaranteed response time as the developers are very busy.

It might need a new updated to the OpenEXR interface with Imagemagick such as a new define.

I do not see anything about density for EXR in their documentation at https://www.openexr.com/documentation/R ... eFiles.pdf
Post Reply