imgkit
imgkit copied to clipboard
How to load from a local image file?
I have included an in my HTML whose src is a local image file. However, the package tries to download it from the network. I believe this bug deserves works to fix.
OSError: wkhtmltoimage reported an error:
Loading page (1/2)
Warning: Blocked access to file /home/david/imageMaster/bg.jfif
Error: Failed to load about:blank, with network status code 301 and http status code 0 - Protocol "about" is unknown
Was also suffering from this problem and this is the way I found to solve it.
1º Insure that in the options you include both this keys:
enable-local-file-access
is to allow wkhtmltoimage access to local files
allow
should be the base absolute path where you have the image, in my case a folder named 'templates' inside my project.
options = {
...,
'enable-local-file-access': "",
'allow': os.path.join(os.path.dirname(__file__), 'templates')
}
2º After that I pass the full path for the image to my html template with resource to Jinja 2
<img class="fancy-img my-logo" src = "{{ logo }}" alt="My Logo"/>
3º I pass the rendered html from Jinja to imgkit and my problem is solved.
Hope that helps