[Thread Prev][Thread Next][Index]

Re: [ferret_users] PyFerret: DPI info for PNG output



Hi Ryo,

I was not aware that PNG images have an optional dots-per-meter specification.  Thus, there currently is no attempt to assign such a value when creating raster image files (such as PNG and JPEG.)  I do now see in Qt there are the QImage.setDotsPerMeterX and QImage.setDotsPerMeterY methods which presumably set these values (and hopefully not anything more than that).  So I can try adding that in.

When PyFerret does need DPI values, for displayed windows it does get the values for the window using the physicalDpiX and physicalDpiY methods of the QMainWindow.  For windows that are not displayed (so using the "-nodisplay" command-line option for PyFerret), the default value of 96 DPI is assigned since there is no display to obtain a value from, and that value was pretty standard at the time.

Best,
Karl


On Tue, Jan 21, 2020 at 1:50 AM Ryo Furue <furue@xxxxxxxxxx> wrote:
Dear Ferret developers,

If I'm not mistaken,  the PNG output from PyFerret (via FRAME/file=image.png ) does not store the correct DPI information in the header of the generated PNG file.  It would be nice if PyFerret actually calculates and stores that information.  (It seems that the DPI value is set always at 72.)

Explanation:  The PDF output includes the physical size of the image.  (Open the image on Acrobat Reader and see "File" > "Properties".)  The PNG format can achieve the same effect by including the DPI information in its header.  For example, if the header says that the image is to be displayed at 100 dots per inch (DPI) and it is 1000 dots x 500 dots, its physical size is 10 in x 5 in.

The number of dots can be specified by the XPIXELS qualifier to the FRAME command, but the physical size of the image should remain the same regardless of the number of dots and should match that of the PDF file.  That means, the DPI value would have to be calculated accordingly to the value of XPIXELS.  (The DPI can be different between the x and y directions, so the y-DPI should also be calculated in accordance with YPIXELS.)

A use case:  I mix PDF images with PNG images in a single document and I want to shrink all of them at a constant ratio, say 50% of the original physical sizes.  For PDF files, you just specify "50%".  For PNG files, you need to know the DPI to know its original size before the ratio "50%" makes any sense.  Without the DPI info associated with the image file, the software (in my case LaTeX) has to assume a DPI value to be able to determine its size within the page.  Because the value the software assumes is wrong, I don't know how much I should shrink it.

Even if you have adjusted the size by trial and error, you have to change the scaling again when you change the value of XPIXELS for the same figure!

Regards,
Ryo





--
Karl M. Smith, Ph.D.
JISAO Univ. Wash. and PMEL NOAA
"The contents of this message are mine personally and do
not necessarily reflect any position of the Government
or the National Oceanic and Atmospheric Administration."

[Thread Prev][Thread Next][Index]
Contact Us
Dept of Commerce / NOAA / OAR / PMEL / Ferret

Privacy Policy | Disclaimer | Accessibility Statement