Login  Register

Re: Unit of measure for image dimensions

Posted by mojavelinux on May 03, 2015; 12:16am
URL: https://discuss.asciidoctor.org/Unit-of-measure-for-image-dimensions-tp3040p3108.html

Mark,

The unit of measure for the height and width of images is pixels by default. In the HTML backend, these values are assigned directly to the width and height attributes on the img tag, as you can see here:

https://github.com/asciidoctor/asciidoctor/blob/master/lib/asciidoctor/converter/html5.rb#L521-L522

The unit of measure matches the default for HTML (CSS pixels).

http://www.w3.org/TR/2014/REC-html5-20141028/embedded-content-0.html#dimension-attributes

I agree this would be good to document.

However, the default stylesheet for Asciidoctor adds responsive characteristics to images, so the pixels are only suggested values. The image will reduce in size to fit the screen as the viewport shrinks. What's really important is the aspect ratio that these numbers capture (as that is preserved). 

The PDF backend (via DocBook) uses these values merely to understand the resolution and aspect ratio of the image. You can set the relative width (relative to the page) using the scaledwidth attribute on the image macro.

image::image.png[Alt Text, 300, 200, scaledwidth=25%]

fopub includes some logic that will scale the image appropriately even when scaledwidth is not set. See:

https://github.com/asciidoctor/asciidoctor-fopub/blob/master/src/dist/docbook-xsl/fo-pdf.xsl#L430-L613

You could copy and reuse this logic in your DocBook pipeline. I go tit from the PressGang team at Red Hat.

Other than that, we don't have a lot of control yet from the AsciiDoc over image scaling in PDF. This is something we're actively discussing in the issue tracker. Your input is welcome.

https://github.com/asciidoctor/asciidoctor-pdf/issues/76

Cheers,

-Dan

On Mon, Apr 27, 2015 at 5:12 AM, hijarian [via Asciidoctor :: Discussion] <[hidden email]> wrote:
There is no indication neither in the docs nor on first three pages of Google search results about what is the unit of measure of the images in AsciiDoc documents. This is significant topic, because AsciiDoc converts both to HTML (native unit is pixel) and to PDF (native unit is either cm or pt).

So, can someone answer and/or add a section to documentation about the following:

* When I write `image::path/to/image.png["Caption",300,200]`, what is those `300` and `200`? Pixels?
* When I produce a PDF from the AsciiDoc document, what DPI it uses, if we are using pixels? Can I control it in some configuration setting?
* If those dimensions are in some abstract units, then, what is the widths of HTML and PDF pages in those units?
* Is there any way to make output-agnostic AsciiDoc document with images? I don't want pixel-perfect identical  layout in both formats, but it would be great to preserve the relative sizes of images at least.

I am using `asciidoctor -b html` for HTML output and `asciidoctor-fopub` for PDF. I will not use `asciidoctor-pdf` until it'll support at least the same feature set as fopub.

Thank you beforehand.


If you reply to this email, your message will be added to the discussion below:
http://discuss.asciidoctor.org/Unit-of-measure-for-image-dimensions-tp3040.html
To start a new topic under Asciidoctor :: Discussion, email [hidden email]
To unsubscribe from Asciidoctor :: Discussion, click here.
NAML



--