Page 1 of 1

How to adjust the resolution keeping the print size?

Posted: 2015-08-14T07:18:51-07:00
by MNeto
Hello. This is my first post. I am a new user ImageMagick.

I'm trying to use ImageMagick to convert a PDF file to PNG format. This PDF file is generated from PSTricks. Basically, within the PDF file there is only a vector image in PostScript (which is what generates PSTricks) with a certain size.

The problem occurs when I try to specify the resolution and size for printing the image. I need the PNG image keep the dimensions specified in the design with PSTricks.

Check if my reasoning is correct: I have a file "in.pdf" which has dimensions of 4.1cm x 4.1cm, which means 1.6in x 1.6in. How I wish a resolution of 600dpi, the image size should be 600 * 1.6 = 960 px.

Then, the command should be (using sh in Linux):

Code: Select all

convert -density 600 -size 960 in.pdf out.png
However, something goes wrong in my calculation, because the output of the command identy shows the following:

Code: Select all

  Geometry: 967x967+0+0
  Resolution: 600x600
  Print size: 1.61167x1.61167
But when I copy the image to the LibreOffice Writer, the image appears too big. LibreOffice can not recognize the expected size of the image that was just 4.1cm x 4.1cm (LibreOffice shows a much higher real size: 21 x 25.64cm).

When you open the image with Gimp, by accessing the image menu -> size for printing, it is shown that the image is 341.84mm x 341.84mm with, or approximately 13.4 in x 13.4 in ... at a resolution of 72 dpi.

If I adjust the size for printing in Gimp to 1.6in, automatically the resolution up to 600dpi, apparently without changing the image. And when I copy this modified version of LibreOffice, it does so with the expected size.

What is going on? How to adjust the resolution with ImageMagick keeping the print size? What are the errors in my procedure?

Thank you in advance.

Note:
Version: ImageMagick 6.8.9-9 Q16 x86_64 2015-01-06.
Kubuntu 15.05 64 bits.
Commando Line Linux (sh).

Re: How to adjust the resolution keeping the print size?

Posted: 2015-08-14T07:41:57-07:00
by snibgo

Code: Select all

  Geometry: 967x967+0+0
  Resolution: 600x600
  Print size: 1.61167x1.61167
So, "convert" gave you what you asked for. If LibreOffice gives you something different, perhaps you are on the wrong forum.

Or do I misunderstand you?

Re: How to adjust the resolution keeping the print size?

Posted: 2015-08-14T13:00:50-07:00
by MNeto
But both the Gimp as LibreOffice showed the same information: a different size image I'm asking (much bigger). In the KDE desktop, Gwenview application shows the image with a very large size. She should have just 1.6in ...

It is right there that is my question. In the information:

Code: Select all

  Geometry: 967x967+0+0
  Resolution: 600x600
  Print size: 1.61167x1.61167
Geometry is in pixels and the others in inches?

What I need is to keep the image print size (leave it with 1.6pol), but leaving her with high resolution (600 dpi or more).

This is possible?

Re: How to adjust the resolution keeping the print size?

Posted: 2015-08-14T13:26:05-07:00
by snibgo
I suggest you post the complete output of "identify -verbose out.png". Also, your PDF. Also, what version of Ghostscript are you using?

Your result shows 967x967 pixels, with 600 pixels per something, and a print size of 1.61167 somethings. What are the units? Inches? Centimeters? Kilometers? I don't know.

Identify and Gimp show your image is square, but LibreOffice says it is not square: 21 x 25.64cm. This is strange.

Re: How to adjust the resolution keeping the print size?

Posted: 2015-08-14T14:13:40-07:00
by MNeto
Thanks for reply.

sorry, I made a mistake in reporting the information. Redid everything again. LibreOffice now shows a square image. When open the menu 'Format image ', it shows 17cm by 17cm (the image in LibreOffice is reduced to fit the margins).

Output of "identify -verbose out.png":

Code: Select all

  Image: out.png
  Format: PNG (Portable Network Graphics)
  Mime type: image/png
  Class: DirectClass
  Geometry: 969x969+0+0
  Resolution: 600x600
  Print size: 1.615x1.615
  Units: Undefined
  Type: Bilevel
  Endianess: Undefined
  Colorspace: Gray
  Depth: 8/4-bit
  Channel depth:
    gray: 1-bit
    alpha: 4-bit
  Channel statistics:
    Pixels: 938961
    Gray:
      min: 0 (0)
      max: 255 (1)
      mean: 246.274 (0.96578)
      standard deviation: 46.3573 (0.181793)
      kurtosis: 24.2583
      skewness: -5.12429
    Alpha:
      min: 0 (0)
      max: 255 (1)
      mean: 7.70069 (0.0301988)
      standard deviation: 42.5589 (0.166898)
      kurtosis: 28.4677
      skewness: -5.48746
  Alpha: graya(255,0)   #FFFFFF00
  Colors: 16
  Histogram:
     24682: (  0,  0,  0,255) #000000 graya(0,1)
      1083: (  0,  0,  0,102) #00000066 graya(0,0.4)
       892: (  0,  0,  0,136) #00000088 graya(0,0.533333)
       694: (  0,  0,  0,187) #000000BB graya(0,0.733333)
       667: (  0,  0,  0, 68) #00000044 graya(0,0.266667)
       625: (  0,  0,  0, 17) #00000011 graya(0,0.0666667)
       608: (  0,  0,  0,238) #000000EE graya(0,0.933333)
       441: (  0,  0,  0,153) #00000099 graya(0,0.6)
       418: (  0,  0,  0,204) #000000CC graya(0,0.8)
       405: (  0,  0,  0, 51) #00000033 graya(0,0.2)
       404: (  0,  0,  0, 34) #00000022 graya(0,0.133333)
       382: (  0,  0,  0,221) #000000DD graya(0,0.866667)
       293: (  0,  0,  0, 85) #00000055 graya(0,0.333333)
       277: (  0,  0,  0,170) #000000AA graya(0,0.666667)
       260: (  0,  0,  0,119) #00000077 graya(0,0.466667)
    906830: (255,255,255,  0) #FFFFFF00 graya(255,0)
  Rendering intent: Undefined
  Gamma: 1
  Background color: graya(255,1)
  Border color: graya(223,1)
  Matte color: graya(189,1)
  Transparent color: graya(0,0)
  Interlace: None
  Intensity: Rec709Luminance
  Compose: Over
  Page geometry: 969x969+0+0
  Dispose: Undefined
  Iterations: 0
  Compression: Zip
  Orientation: Undefined
  Properties:
    date:create: 2015-08-14T17:49:54-03:00
    date:modify: 2015-08-14T17:49:54-03:00
    icc:copyright: Copyright Artifex Software 2011
    icc:description: Artifex Software sRGB ICC Profile
    icc:manufacturer: Artifex Software sRGB ICC Profile
    icc:model: Artifex Software sRGB ICC Profile
    pdf:Version: PDF-1.5 
    png:bKGD: chunk was found (see Background color, above)
    png:cHRM: chunk was found (see Chromaticity, above)
    png:iCCP: chunk was found
    png:IHDR.bit-depth-orig: 8
    png:IHDR.bit_depth: 8
    png:IHDR.color-type-orig: 4
    png:IHDR.color_type: 4 (GrayAlpha)
    png:IHDR.interlace_method: 0 (Not interlaced)
    png:IHDR.width,height: 969, 969
    png:pHYs: x_res=600, y_res=600, units=0
    png:text: 3 tEXt/zTXt/iTXt chunks were found
    png:tIME: 2015-08-14T20:49:54Z
    signature: 9e7290d5b7003c39d9c9676fb371bb99048421acb0b357ce9fcb841c4d9e28c1
  Profiles:
    Profile-icc: 2576 bytes
  Artifacts:
    filename: out.png
    verbose: true
  Tainted: False
  Filesize: 23.3KB
  Number pixels: 939K
  Pixels per second: 31.3MB
  User time: 0.040u
  Elapsed time: 0:01.030
  Version: ImageMagick 6.8.9-9 Q16 x86_64 2015-01-06 http://www.imagemagick.org
Link for original in.pdf (this is a mathematical image, with a circle. This is a test image): http://mnetox.atwebpages.com/in.pdf.

My Ghostscript version:

Code: Select all

GPL Ghostscript 9.15 (2014-09-22)
Copyright (C) 2014 Artifex Software, Inc.  All rights reserved.
Regarding the units used ...

Really I do not know what is the real meaning of the output of the identify command. He does not say the units used in the output.
What I do know are the units I'm using at the input: the original have PDF 4.1cm x 4.1cm (1.6in x 1.6in).

In the command below, I have used pixels and inches ('m new to ImageMagick and not fully understand the functioning of dpis):

Code: Select all

convert -density 600 -size 960 in.pdf out.png
Thanks.

Re: How to adjust the resolution keeping the print size?

Posted: 2015-08-14T14:16:15-07:00
by fmw42
I do not know if this relates, but some others have had trouble with GS 9.15 and have found that the most recent version, 9.16, solved their problems. So you might try upgrading your GS.

Re: How to adjust the resolution keeping the print size?

Posted: 2015-08-14T15:18:35-07:00
by snibgo
Try it with "-units":

Code: Select all

convert -density 600 -units pixelsPerInch in.pdf c.png
EDIT: And don't use "-size". Why do you want it?

Re: How to adjust the resolution keeping the print size?

Posted: 2015-08-14T16:37:05-07:00
by MNeto
Try it with "-units":

Code: Select all
convert -density 600 -units pixelsPerInch in.pdf c.png

EDIT: And don't use "-size". Why do you want it?
Thank you! It works now!

I do not understand 100% on the relationship between image size and dpis. So I mistakenly used the size option.

Indeed, the command worked. But still I do not know how it works.
Could you explain me?

Thank you, snibgo.

fmw42, I updated the ghostscript to version 9.16 (compiled straight from the source code), but the behavior was the same as the previous one. The problem was even at my command posted, and the solution was what snibgo pointed.

Thanks for all.

Re: How to adjust the resolution keeping the print size?

Posted: 2015-08-14T16:54:20-07:00
by MNeto
Completing what was said in the previous post, the two forms work:

units in inches:

Code: Select all

convert -density 600 -units pixelsPerInch in.pdf out.png
units in pixels (or dots) per cm (600dpi = 236.2205dpcm)

Code: Select all

convert -density 236.2205 -units PixelsPerCentimeter in.pdf out.pdf
From what I understand, you need to specify the unit whenever you specify the resolution?

"DotsPerInches" is the same as "PixelsPerInches"? That is, "pixels" is the same as "dots"?

Re: How to adjust the resolution keeping the print size?

Posted: 2015-08-14T21:36:43-07:00
by snibgo
If units are undefined, most software assumes inches. But we should always be explicit: when giving density, we should also give units.

Yes, "pixels" are the same as "dots".

Re: How to adjust the resolution keeping the print size?

Posted: 2015-08-15T05:31:20-07:00
by MNeto
Thank you!