Open Omikhleia opened 2 years ago
If anyone is interested to contribute to this topic at some time, here is my "limited" attempt so far, in the shape of an experimental printoptions package for SILE 0.12.5:
SILE.outputter.drawImage
so that images are downsized (and optionally flattened) to match a target resolution (relying on ImageMagick's convert).\svg
command so that SVG files can be optionally rasterized (relying both on Inkscape and ImageMagick's convert)Without support for retrieving the original image dimensions, it might create a bunch of useless (but harmless) files and it does not warn upon under-resolution, but at least it may help if one has high resolution images that can be reduced according to the actual size they'll take on the page and the expected resolution in DPI. Rasterization of vector images (especially when huge) is also something that is quite often requested by printers. (Flattening here just applies to the image, so might not be what the printer expects if there's a text over an image, but still it can help checking ordering).
For now, I'll live with this quick experimental version and won't probably work on it again soon, but this might be interesting to look anyway, for inspiration and discussion.
This is a proposal for discussion about improving image inclusion and converters.
First, my assumptions (which may need some more informed check) from a brief look at the libtexpdf C code:
\img[width=...]
relatively to its natural (claimed) size, it uses a transformation matrix. The image is not up/down-sampled, just scaled.Now consider I got that nice PNG image which, at its natural size, takes a 2 inches (5.08 cm) width on my page. Since the natural size of the image (see #1267) depends on the resolution set in its metadata, it could actually mean several things, e.g. (1) 1200 pixels and a resolution 600 px/inch, (2) 600 px and a resolution 300 px/inch, or (3) 300 px and a resolution 150 px/inch.
Use case 1 These all end up, on my page, occupying the same width... but they do not have the same quality in print. Now, say my printer supports 300 dpi (ink dots per inch). Notwithstanding Shannon's law here, one could consider (1) to have a negative useless impact on the size of my PDF, (2) to be just fine and (3) to be real bad for print, with a blurry image...
Could SILE warn me about it? Actually, it would need but a small modification to the C code. The natural size is retrieved via
SILE.outputter.getImageSize
, which actually relies onget_image_bbox
(fromsrc/imagebbox.c
). The latter relies on libtexpdf, but at this point it has the "density", here supposedly expressed in pt/inch. Note the pt (point): libtexpdf retrieves the metadata (which can already be in various units depending on the image format). For a PNG, it gets them as px/m (meters, yes, thankslibpng
... er... thanks actually PNG format), converts that to px/inch and multiplies by 72 (1pt = 1/72in), so we actually end up with a density in pt/inch. Anyhow, we could return that density up to SILE's Lua (we just need to either to convert it back to a resolution, or call it a density indeed but avoid using a misleading "ppi" unit in its description!).Say I didn't check these things and went up naively for
\img[width=10cm...]
. What it means is that (1) now resolves to 304.8 px per inches, (2) to 152.4 px/in and (3) to 76.2 px/in = In this case, (1) is just fine without being over-dimensioned, and (2-3) are both bad. The above-mentioned warning would of course have to take into account the actual target size.Use case 2 Now I have the same very document including that image, used in two different document masters, one for print (6x9 pages, nice font, etc... and it expects a 300 dpi quality at least for images) and one sent by mail to reviewers as a PDF (A4, large interline-skips, etc... and I'd be happy for it to only have a 100 dpi quality or even lower for images, to make it much smaller). I am not fond of having two versions of the same image for both resolution targets and switch them manually, as seen it also depends on the actual size in the document and I cannot check all images... Could SILE provide a mechanism to automatically convert and include the appropriate image? That would also solve my above issue with the 600-px/in oversized image.
I am tempted to use
converters
registrations - the current code only passes the src and format expectations here, but could be modified to also get the target width and height. However, it's involved too soon (as a mere wrapper around\img
) so doesn't know the image actual properties yet. It does seem doable to invoke the outputter here again to retrieve them, though perhaps we could avoid a double call and have something more low-level?Recap
begin[papersize=..., resolution=300, ...]{document}
)\img
to warn about under-resolution.