how to instruct wkhtmltoimage (not pdf) to render a high dpi image?
Asked Answered
S

1

7

Hi I'm trying to use wkhtmltoimage to generate a JPEG format image.

I've tried --dpi then got Unknown long argument --dpi.

Shooin answered 24/11, 2015 at 3:42 Comment(0)
D
5

You can try to use the --zoom parameter for this. Assuming you want a 300 dpi image and your system's default resolution is 96 dpi, you'd need to set it to 300 / 96 = 3.125. Of course you have to scale up your virtual screen width as well. So further assuming you want to capture a website as it is displayed at a screen width of 1000 pixels, you also need to set --width to 1000 * 3.125 = 3125.

The complete command could look like this:

wkhtmltoimage
    --disable-smart-width \
    --zoom 3.125 \
    --width 3125 \
    <input-url> \
    <output-file>

I'm not sure though, how the zoom affects images on the website, that were originally scaled down. Also depending on your further processing of the image you might need to adjust the dpi value in the metadata of the output file. In this case it would still be set to 96 dpi.

Of course it would be nice to have the --dpi parameter of wkHTMLtoPDF work here as well and do the calculations internally ;)

Devotion answered 24/7, 2018 at 7:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.