How can I generate a screenshot of a webpage using a server-side script?
Asked Answered
L

4

19

I need a server-side script (PHP, Python) to capture a webpage to a PNG, JPG, Tiff, GIF image and resize them to a thumbnail.

What is the best way to accomplish this?

See also:

Leede answered 3/4, 2009 at 13:35 Comment(0)
H
14

You can probably write something similar to webkit2png, unless your server already runs Mac OS X.

UPDATE: I just saw the link to its Linux equivalent: khtml2png

See also:

Holocaust answered 3/4, 2009 at 13:46 Comment(2)
webkit2png can be compiled from source - works without problems on Linux as well (tested on Ubuntu 10.04 x64)Moneywort
According to https://mcmap.net/q/247063/-web-page-screenshots-with-php wkhtml2image shall be the best (code.google.com/p/wkhtmltopdf/downloads/list)Erose
L
7

What needs to happen is for a program to render the page and then take an image of the page. This is a very slow and heavy process but it can be done in PHP on Windows.

Also check the comments in the documentation article.

For python I'd recommend reading this article. It highlights some of the solutions.

There are services you can also call (via some API) that will return you an image. But usually they cost (WebShots for example)

Locomotive answered 3/4, 2009 at 13:39 Comment(0)
L
2

You'll need to:

  • read the webpage and all the its multimedia content (images, flash, etc)
  • utilize a browser rendering engine to render the webpage
  • take a screenshot and save it as image

first and third steps are easy, the second step is more challenging ;)

Landa answered 3/4, 2009 at 13:41 Comment(0)
L
0

If you are using php, you could use imagegrabscreen (PHP 5 >= 5.2.2). Imagegrabscreen: captures the whole screen.

Lexie answered 2/11, 2009 at 0:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.