Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to load from a local image file? #73

Open
XieGuochao opened this issue Jun 18, 2021 · 1 comment
Open

How to load from a local image file? #73

XieGuochao opened this issue Jun 18, 2021 · 1 comment
Assignees
Labels

Comments

@XieGuochao
Copy link

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

@ltfavas
Copy link

ltfavas commented Jan 6, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants