vgalin / html2image

A package acting as a wrapper around the headless mode of existing web browsers to generate images from URLs and from HTML+CSS strings or files.
MIT License
354 stars 43 forks source link

Endless repetition of screenshot calls if errors were printed, but image generation succeeded #105

Open scorpion81 opened 1 year ago

scorpion81 commented 1 year ago

When html2image is invoked from a python script inside blender 3.4, under linux, like in the following snippet

from html2image import Html2Image

w = 320
h = 240
self.image_name = 'red_page.png'

custom_flags=['--disable-software-rasterizer', '--disable-gpu', '--disable-features=DefaultPassthroughCommandDecoder']
hti = Html2Image(size=(w, h), custom_flags=custom_flags)
html = """<h1> An interesting title </h1> This page will be magenta"""
css = """ body {
                  background: darkred;
               } 
          h1 {
                font-size: 80px; 
                color: white; 
             }
      """
self.image_path = hti.screenshot(html_str=html, css_str=css, save_as=self.image_name)[0]

this message is printed repeatedly:

[0316/203414.241436:ERROR:gpu_init.cc(525)] Passthrough is not supported, GL is disabled, ANGLE is 
[0316/203414.339199:WARNING:bluez_dbus_manager.cc(247)] Floss manager not present, cannot set Floss enable/disable.
17928 bytes written to file /home/xxx/red_page.png

Obviously the image generation succeeded anyways, i also get an according output image like red_page

I tried with changing settings in chrome and chromium , passing different flags etc. Without the mentioned additional flags, there were even more error messages like:

[0316/204905.757468:WARNING:bluez_dbus_manager.cc(247)] Floss manager not present, cannot set Floss enable/disable.
[0316/204906.567913:ERROR:gpu_process_host.cc(952)] GPU process exited unexpectedly: exit_code=139
[0316/204906.567973:WARNING:gpu_process_host.cc(1302)] The GPU process has crashed 1 time(s)
[0316/204907.402546:ERROR:gpu_process_host.cc(952)] GPU process exited unexpectedly: exit_code=139
[0316/204907.402586:WARNING:gpu_process_host.cc(1302)] The GPU process has crashed 2 time(s)
[0316/204908.219163:ERROR:gpu_process_host.cc(952)] GPU process exited unexpectedly: exit_code=139
[0316/204908.219189:WARNING:gpu_process_host.cc(1302)] The GPU process has crashed 3 time(s)
[0316/204909.049910:ERROR:gpu_process_host.cc(952)] GPU process exited unexpectedly: exit_code=139
[0316/204909.049939:WARNING:gpu_process_host.cc(1302)] The GPU process has crashed 4 time(s)
[0316/204909.896793:ERROR:gpu_process_host.cc(952)] GPU process exited unexpectedly: exit_code=139
[0316/204909.896817:WARNING:gpu_process_host.cc(1302)] The GPU process has crashed 5 time(s)
[0316/204910.737015:ERROR:gpu_process_host.cc(952)] GPU process exited unexpectedly: exit_code=139
[0316/204910.737044:WARNING:gpu_process_host.cc(1302)] The GPU process has crashed 6 time(s)
[0316/204910.747371:ERROR:gpu_init.cc(525)] Passthrough is not supported, GL is disabled, ANGLE is 
[0316/204910.851666:WARNING:gpu_process_host.cc(975)] Reinitialized the GPU process after a crash. The reported initialization time was 0 ms
17928 bytes written to file /home/xxx/red_page.png

which basically causes the script calling into html2img to hang indefinitely.

Hmm if bytes were actually written into the image, is there a way to atleast stop the repetetition of the calls ? Together with the many printouts this massively drops the performance, or even more exactly spoken, i have to hit ctrl c a few times to break out of that loop (but finally I get the image)

Do you maybe have some hints what flag combinations might stop those error outputs completely ?

scorpion81 commented 1 year ago

Forget to mention this: https://stackoverflow.com/questions/67501093/passthrough-is-not-supported-gl-is-disabled I tried the flags --disable-software-rasterizer', '--disable-gpu', '--disable-features=DefaultPassthroughCommandDecoder' according to this post, but no avail unfortunately.

fvarrui commented 7 months ago

Hi @scorpion81! Do you know how to omit XXXX bytes written to file /path/to/image message?

I tried to redirect standard output but it's not working:

import contextlib

hti = Html2Image()
hti.output_path = destination_dir
with open(os.devnull, 'w') as devnull:
    with contextlib.redirect_stdout(devnull):
            hti.screenshot(html_str=html, save_as=img_file)