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
344 stars 44 forks source link

Screenshot size #103

Closed Rolln-dev closed 1 year ago

Rolln-dev commented 1 year ago

Screenshot does not seem to honor setting the size parameter any longer.

Using Chrome browser Version 111.0.5563.65 (Official Build) (64-bit)

LukeSchmitt96 commented 1 year ago

Didn't see this issue before posting my comment in https://github.com/vgalin/html2image/issues/102#issuecomment-1465278385, but it seems to be a bug with Chromium.

AnnaStimp commented 1 year ago

How can I get a 1080x1920 image now? size=(1080, 1920) dont work

vgalin commented 1 year ago

At this point and for the moment, the easiest solution would probably be to downgrade Chromium's version on your machine. The 111.x version is breaking everything for some reason.

jackward-countdown commented 1 year ago

For anyone that wants a quick example of downgrading google-chrome-stable in a Dockerfile (Debian):

# Install Chromium. v111 has a bug with image size not being respected
# Can unlock version when issue is resolved: https://github.com/vgalin/html2image/issues/103
ARG CHROME_VERSION="110.0.5481.177-1"
RUN \
  wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - && \
  echo "deb http://dl.google.com/linux/chrome/deb/ stable main" > /etc/apt/sources.list.d/google.list && \
  apt-get update && \
  wget --no-verbose -O /tmp/chrome.deb https://dl.google.com/linux/chrome/deb/pool/main/g/google-chrome-stable/google-chrome-stable_${CHROME_VERSION}_amd64.deb \
  && apt-get install -y /tmp/chrome.deb \
  && rm /tmp/chrome.deb \
  rm -rf /var/lib/apt/lists/*
andyolivers commented 1 year ago

Hi. I'm facing the same issue, I can't update the figure size and in the previous releases. In addition, when I try to use the previous versions it doesn't export any png. Is this fixed?

vgalin commented 1 year ago

Hi. I'm facing the same issue, I can't update the figure size and in the previous releases. In addition, when I try to use the previous versions it doesn't export any png. Is this fixed?

Please try to update your package, python -m pip install --upgrade html2image.

andyolivers commented 1 year ago

Just did so and the issue persists. All figures are being exported with the same size

mustafa-syed commented 1 year ago

For anyone that wants a quick example of downgrading google-chrome-stable in a Dockerfile (Debian):

# Install Chromium. v111 has a bug with image size not being respected
# Can unlock version when issue is resolved: https://github.com/vgalin/html2image/issues/103
ARG CHROME_VERSION="110.0.5481.177-1"
RUN \
  wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - && \
  echo "deb http://dl.google.com/linux/chrome/deb/ stable main" > /etc/apt/sources.list.d/google.list && \
  apt-get update && \
  wget --no-verbose -O /tmp/chrome.deb https://dl.google.com/linux/chrome/deb/pool/main/g/google-chrome-stable/google-chrome-stable_${CHROME_VERSION}_amd64.deb \
  && apt-get install -y /tmp/chrome.deb \
  && rm /tmp/chrome.deb \
  rm -rf /var/lib/apt/lists/*

The following works from the terminal (ref: https://stackoverflow.com/questions/32248164/how-to-downgrade-chrome-on-ubuntu-and-disable-auto-update):

sudo wget http://dl.google.com/linux/chrome/deb/pool/main/g/google-chrome-stable/google-chrome-stable_110.0.5481.177-1_amd64.deb && \ sudo dpkg -i google-chrome-stable_110.0.5481.177-1_amd64.deb && \ sudo apt-mark hold google-chrome-stable && \ google-chrome-stable --version \

mustafa-syed commented 1 year ago

this works for me in Jupyter Notebook.

andyolivers commented 1 year ago

How can I do it on a mac or windows?

mustafa-syed commented 1 year ago

How can I do it on a mac or windows?

Download link: https://chromium.cypress.io/ Before you begin downgrading, you should have a look at the related issues here: https://browserhow.com/how-to-downgrade-and-install-older-version-of-chrome/

Adi01010101 commented 1 year ago

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(......)
vbasov007 commented 1 year ago

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(......)

worked for me too

jrb-github commented 1 year ago

For those of us who don't fully control the chromium version on the machines where our scripts using html2image will run - does anyone know if this has been reported against chromium yet?

bishely commented 1 year ago

I've managed to bypass this on Windows by installing an older portable version of Chrome v109 -

Thank you! I've been tearing my hair out for hours trying to solve this: the portable workaround is just what I needed!

LukeSchmitt96 commented 1 year ago

does anyone know if this has been reported against chromium yet?

See Chromium bug tracker 1424464. Apparently the fix will be available in 113.

rinavolu commented 1 year ago

With latest html2image and latest chromium didnt worked. As suggested downgrading helps me. Thank you 🫡

At this point and for the moment, the easiest solution would probably be to downgrade Chromium's version on your machine. The 111.x version is breaking everything for some reason.

plopidou commented 1 year ago

another quick hack I had to use: . take a screen at a larger size then expected . PIL crop() the image to the desired dimensions

a bit longer, but works flawlessly.

Kasherpete commented 1 year ago

Is this issue fixed? I know this is a problem with Chromium, and it does not look like the latest version has dropped yet.

georgewesley commented 1 year ago

This still appears to be an issue with Chrome 112

jrb-github commented 1 year ago

Earlier in this thread @LukeSchmitt96 posted this link (thanks Luke!) which includes precise chromium versions both where the issue was introduced, and where it is fixed. How and when the fixed chromium version is up-took via your browser of choice (i.e. mainline Chrome, Edge, etc.) will vary depending on which you use. I am using Edge, and have been watching this page. As for html2image, I don't know if it has been explicitly stated, but my guess is no change will be made to fix this, assuming that the fix to chromium works as expected.

Kasherpete commented 1 year ago

Okay, I will probably use Selenium to take a screenshot (that works for some reason with resizing idk why) and do that until the newest version of Chromium drops.

LukeSchmitt96 commented 1 year ago

Apparently the fix will be available in 113

Chrome 113 has been released and includes the fix for this issue.