Forum Documentation

How does image-resolution work?

RBK
Reading the documentation, I fail to understand how Prince maps image resolutions to PDF pages:

Let's assume there is an image embedded in HTML like so: <img alt="a genuine foo" src="foo.png" width="300" />. Apparently, Prince then makes an assumption about what length the 300 correspond to on the PDF page which is independent of prince-image-resolution. Is that intentional? What is it? Is there a way to override it?
mikeday
Specifying width="300" is equivalent to style="width: 300px", applied by this rule in the default HTML style sheet:
*[width] { width: attr(width, px, attr(width, percent)) }

Since you have specified a size that the image should take up on the page, the image resolution (eg. DPI) is no longer relevant, and will be ignored. The image resolution (DPI) will only be used when no other width information is available.
RBK
Let me try to rephrase my question.
When the image does come with size attributes whose units are pixels: how big does Prince assume pixels map to distance on the paper?
I now recall that CSS defines a reference pixel as the visual angle of one pixel on a device with a pixel density of 96dpi and a distance from the reader of an arm’s length(!). Is it that? If it is, can it be overridden in Prince somehow?
mikeday
Default measurement for px units in Prince is 96dpi, which cannot be overridden. So if you say "width: 96px" on an element that is exactly equivalent to saying "width: 1in".
RBK
mikeday wrote:
Default measurement for px units in Prince is 96dpi, which cannot be overridden. So if you say "width: 96px" on an element that is exactly equivalent to saying "width: 1in".

This strikes me as something that could be enhanced: The way it is now, when default resolution is 192px, a 96px image is 1/2 inch wide. But when one adds style="width:95px" the size jumps abruptly to just under one inch wide.
mikeday
Right, it's a bit tricky to satisfy everyone in this situation, as some documents have style sheets that size text in pixels, eg. 16px, but then substitute high-resolution images at 300dpi specifically for printing. The easiest solution is probably to avoid pixel measurements for layout in documents intended for printing.