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.
User avatar
fmw42
Posts: 26383
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 »

I was giving syntax for the convert or magick command only. It did not apply to mogrify. I was just commenting on your syntax which I believe is in error.

The OP was asking about a raster image. I assume he was using convert. But it was not specified. My answer covered raster files and a different syntax for vector files. However, I will modify my comment for vector files. Set the units and density before the input, read the input, set the units and density after reading the input and before the output to set the density for the output if different from what was used for the input

Code: Select all

convert -units input_units -density input_density input.pdf ....processing.... -units output_units -density output_density output.suffix
For a raster input, you do not need the input units or density.

john1120
Posts: 11
Joined: 2017-05-31T04:29:13-07:00
Authentication code: 1151

Re: convert image 75 dpi to 300 dpi

Post by john1120 »

I was giving syntax for the convert or magick command only. It did not apply to mogrify.
Yes, we talk about convert/magick.
I was just commenting on your syntax which I believe is in error.
You mean this syntax?

Code: Select all

magick -units PixelsPerInch image -density 300 resultimage
But this is simply copy-and-paste from Drarakel's post. I simply replaced "convert" with "magick".

It seems he talked about raster input and he said to use the code you can see above. He puts "-units" before input and "-density" after.

On the other hand, you say that both "-units" and "-density" should be after input.

So, you disagree with him?

User avatar
fmw42
Posts: 26383
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 »

Yes, I disagree.

john1120
Posts: 11
Joined: 2017-05-31T04:29:13-07:00
Authentication code: 1151

Re: convert image 75 dpi to 300 dpi

Post by john1120 »

I see, thanks. So, there are two different opinions from experienced ImageMagick users. I will take it into consideration when I face with this issue in the wild.

User avatar
fmw42
Posts: 26383
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 »

That syntax you showed may work for Imagemagick 6 as it was more forgiving. Also the units setting will pass past the input image. So it will likely work for setting the output units as well. The density could have been put before the input also, since it was a setting. Operators should not be placed before the input image properly in Imagemagick 6. But that may still work. See https://imagemagick.org/Usage/basics/#syntax and https://imagemagick.org/Usage/basics/#options and https://imagemagick.org/Usage/reference.html

But note that Imagemagick 7 is much more strict on syntax and a command with sloppy syntax in Imagemagick 6 may fail in Imagemagick 7. See https://imagemagick.org/script/porting.php#cli.

john1120
Posts: 11
Joined: 2017-05-31T04:29:13-07:00
Authentication code: 1151

Re: convert image 75 dpi to 300 dpi

Post by john1120 »

That syntax you showed may work for Imagemagick 6 as it was more forgiving.
Yes, that post by Drarakel was about ImageMagick 6. It was posted 2011-03-08, while
  • the stable version of ImageMagick 7 was released 2015-11-28.
  • its alpha versions were available since 2013-03-09
It will take some time to study the links you provided :)

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

Re: convert image 75 dpi to 300 dpi

Post by snibgo »

FWIW, I agree with Fred. IM's behaviour has changed since Drarakel wrote in 2011.

For IM v7, we should always think about the obvious, natural order of operations. We read a raster image from a file, then change its density, then write a new file.

Code: Select all

magick in.png -density 350 -units pixelsperinch out.png
If we set density and units before reading the file, it happens to work, but I don't recommend it.

If the input is vector, we may set density and units before reading it, to affect the rasterization and hence the final size in pixels. Then we can set the density and units after reading it, to change just the metadata. Finally, we write to a file.

For mogrify, I'm not sure of the most appropriate order, especially if reading vector images.
snibgo's IM pages: im.snibgo.com

john1120
Posts: 11
Joined: 2017-05-31T04:29:13-07:00
Authentication code: 1151

Re: convert image 75 dpi to 300 dpi

Post by john1120 »

@snibgo Easy to understand, thanks.

User avatar
fmw42
Posts: 26383
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 »

At one time it was important to put the units before the density. I do not think that is still important, but I always do that anyway.

Locked