Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do PNGs (or JPGs) have a DPI? Or is it irrelevant when building for retina?

Tags:

A simple question that I have been having great difficulty finding a definitive answer to: do PNG files have a DPI? Or perhaps more importantly, is it even relevant when building retina-enabled sites/apps?

I've just received PSD assets from our designer for a retina iPad app that I must convert into HTML for display within the app. Typically, I receive such files as 2048x1536 @ 72 DPI -- double size but standard screen DPI. I then typically use CSS to tell the browser how to display it.

But this time the designer was instructed to provide his PSDs at 1024x768 @ 144 DPI (standard size but double DPI.) I believe this is incorrect, as the DPI setting within Photoshop is intended for print purposes. Plus, when I save something from a 144 DPI PSD as a PNG or JPG, it is exactly the same as one saved from a 72 DPI (or 30,000 DPI for that matter) PSD. DPI doesn't seem to be reflected in either any setting that I can see in the resultant file nor in a different file size. It seems, at best, metadata.

So, it's my understanding that DPI isn't relevant here, and we should simply be asking for double-sized assets for retina projects, but I would like some confirmation/clarity on the issue before asking for new assets. I work with many designers that are transitioning from print backgrounds so this is a common issue I encounter and I'd like to be able to provide better guidance with our requirements in the future.

like image 485
gbanks Avatar asked Dec 05 '14 19:12

gbanks


People also ask

Does PNG use DPI?

The PNG-standard specifies an optional header with the DPI. In the PNG file two 4-byte numbers gives the pixels per meter og the width and height, which can be converted to DPI by multiplying with 0.0254 meters/inch. You can see the DPI of the image by using, for example, GIMP by using image -> image properties.

Are PNGs higher quality than JPGS?

The Difference between PNG and JPG JPEG or JPG stands for Joint Photographic Experts Group, with so-called “lossy” compression. As you might have guessed, that is the biggest difference between the two. JPEG files' quality is significantly lower than that of the PNG files.

Are PNGs always 72 DPI?

Yeah, raster images like PNG and JPG are always locked at 72dpi. But instead of saving it at 300dpi for example, you can also save it at the 4.16x size and then bring it back to the original size where you need to use it.

Does PNG have a resolution?

PNG stores resolution internally as pixels per meter, so when calculating back to pixels per inch, some programs may show excessive decimal digits, perhaps 299.999 ppi instead of 300 ppi (no big deal).


2 Answers

DPI is the relationship between an image's pixel dimensions and the physical size it appears (or should appear) when displayed, regardless of how it's displayed (screen, print, whatever). No image format inherently has a DPI, but any actual image that's made of pixels and should appear with a certain physical size has a DPI.

You're correct that DPI is just metadata as far as an image file is concerned. The image itself is a grid of pixels with no inherent physical size, but the DPI value expresses an intended physical size. For example, an image that's 144 pixels wide with a DPI of 144 should appear one inch wide when displayed, but an image that's 144 pixels wide with a DPI of 72 should appear two inches wide when displayed.

The DPI value stored in an image can be used to scale it automatically to the correct physical size when it's displayed on a device whose DPI is also known. For example, a 144dpi image displayed on a 72dpi monitor should be scaled by 50% in each dimension, so that 144 pixels (one inch) of image is mapped to 72 pixels (one inch) of monitor surface. Web browsers, however, typically don't do this; image pixels are simply mapped directly to screen pixels, so you have to manually scale your images to have pixel dimensions that are appropriate for the monitor where they'll be displayed.

You mentioned getting images at 2048x1536 @ 72 DPI and 1024x768 @ 144 DPI, but those are not at all equivalent. A 2048x1536 72DPI image should appear about 28.4 inches wide (2048/72), but a 1024x768 144DPI image should appear about 7.1 inches wide (1024/144). Are you sure you didn't mean 2048x1536 @ 144DPI and 1024x768 @ 72DPI (both of which are 14.2 inches wide)?

BTW, conventional (non-retina) monitors these days are typically 96 to 100 DPI, not 72. For example, my 20-inch Dell 2007WFP has pixel dimensions of 1680x1050. That's about 1981 pixels on the diagonal, which is about 99 pixels per inch. The "px" unit in CSS is actually defined as 1/96th of an inch, which may correspond to more than one physical pixel on a high-DPI screen.

like image 91
Wyzard Avatar answered Oct 07 '22 07:10

Wyzard


PNG does have the ability to store pixels/meter, separately for the X and Y direction, in the PNG "pHYs" chunk. Unfortunately this does not allow exact conversions (72 dpi is 2834.64566929 pixels per meter which is stored as 2835 pixels/meter and when converted back to DPI becomes 72.009); some people find this disturbing.

JPEG also can store X_density and Y_density, in units pixels/inch or pixels/cm.

like image 34
Glenn Randers-Pehrson Avatar answered Oct 07 '22 06:10

Glenn Randers-Pehrson