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

screenshots all black when using html file or string #117

Open stormyweathers opened 1 year ago

stormyweathers commented 1 year ago

Hey there,

Im using V2.0.3 with python 3.8.3

I can't get the basic functionality to work on my machine. It works if I fetch an html page from the web, but not from local sources.

This example works fine

from html2image import Html2Image
hti = Html2Image()
hti.screenshot(url='https://www.python.org', save_as='python_org.png')

but if I download the webpage locally, and try it again

hti.screenshot(html_file='test.html')

it fails.

I've tried with simpler examples, and html strings as well. All local sources give just a blank black image.

datawookie commented 1 year ago

I have the same problem.

vgalin commented 1 year ago

I am not currently able to reproduce this issue, could you provide the following ?

ghost commented 1 year ago

I just experienced this myself. I can provide the html and chrome version.

chrome version: 114.0.5735.199 (Official Build) (64-bit) (cohort: Stable Installs & Version Pins) html:

<head><meta` http-equiv="refresh" content="1"></head><center><h2>今日の予約</h2><table border="1" class="dataframe">
  <thead>
    <tr style="text-align: center;">
      <th></th>
      <th>小</th>
      <th>大</th>
      <th>答なし</th>
      <th>✖</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>1</th>
      <td></td>
      <td></td>
      <td>山田太郎</td>
      <td></td>
    </tr>
    <tr>
      <th>2</th>
      <td></td>
      <td></td>
      <td>浅川良太</td>
      <td></td>
    </tr>
    <tr>
      <th>3</th>
      <td></td>
      <td></td>
      <td>鈴木亜美</td>
      <td></td>
    </tr>
    <tr>
      <th>4</th>
      <td></td>
      <td></td>
      <td>鹿見葛城</td>
      <td></td>
    </tr>
  </tbody>
</table></center>

*These names are all made up for testing purposes. No personal/private data here.

Expected output should be something like this: image

Actual output looks like this:

sortedlist

jjpaulo2 commented 1 year ago

Hi @fkkjohn.

I got the same error, and after I read this comment from @vgalin, I could notice that this could be just a permission problem.

Actually I am using the lib as above, and it is working fine to me.

htm = Html2Image(
    custom_flags=[
        '--no-sandbox'
        '--remote-allow-origins=*',
        '--hide-scrollbars'
    ],
    temp_path=f'{getcwd()}/.tmp'
)
ghost commented 1 year ago

Thank you, Paulo. I read the link you sent, but I'm not running Ubuntu on this computer. It's Windows 10. It could still be a permission problem as you suggest, so I'll have a look. However, I've since moved on to a different solution, so it's not a priority for me at the moment.

Either way, thank you very much for the reply.

tmblog commented 1 year ago

I am getting the same, have tried putting in a background color via css but still the same. Windows and Chrome Version 116.0.5845.141 (Official Build) (64-bit)

UPDATE: The default bg color is 000000 worked after changing the default:

hti = Html2Image(
    custom_flags=['--default-background-color=FFFFFF', '--hide-scrollbars']
)