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

Background is not transparent anymore #113

Open
LukasReindlGit opened this issue Apr 14, 2023 · 3 comments
Open

Background is not transparent anymore #113

LukasReindlGit opened this issue Apr 14, 2023 · 3 comments

Comments

@LukasReindlGit
Copy link

LukasReindlGit commented Apr 14, 2023

When I ran this code I was used to get a transparent image with only the red text.
Now the background is white.
Is it a known issue based on some chrome version?
Since I am running my code in a docker container, I am quite flexible.

def renderImage(html, css, size, outputPath):
    hti = Html2Image(custom_flags=['--no-sandbox'])
    img = hti.screenshot(html_str=html, css_str=css, save_as='htmlToImage.png', size=size)
    os.chmod(img[0], 0o0777)
    shutil.move(img[0], outputPath)
    print('image created', outputPath)
    return outputPath

if __name__ == '__main__':
    html = '<html><body><h1>Hello, World!</h1></body></html>'
    css = 'h1 { color: red; }'
    renderImage(html, css, (720,1280), 'test.png')
@SmartWashingMachine
Copy link

SmartWashingMachine commented Apr 16, 2023

I had the same issue. Not sure what version of Chrome is causing this but Adi's solution for another issue also ended up fixing this issue for me. (Windows)

Fix:

I've managed to bypass this on Windows by installing an older portable version of Chrome v109 - googlechromeportable64_109.0.5414.120_online.paf

(https://sourceforge.net/projects/portableapps/files/Google%20Chrome%20Portable/) and using in my program. I installed in the same folder.

hti=Html2Image(browser_executable='GoogleChromePortable64/App/Chrome-bin/chrome.exe')
hti.size=(2046,2046)
...
hti.screenshot(......)

Tested on latest html2image (2.0.3)

@vgalin
Copy link
Owner

vgalin commented May 20, 2023

For now, you can use the --default-background-color flag to force transparent background color, like so:

hti = Html2Image(custom_flags=['--no-sandbox', '--default-background-color=00000000'])

@kzu
Copy link
Contributor

kzu commented Jul 6, 2023

Would be nice to be able to pass those custom flags when using the CLI too. Right now, there doesn't seem to be a way to do so?

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

No branches or pull requests

4 participants