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

纵然是瞬间 提交于 2019-11-26 13:23:31

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:

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)

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 ;)

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!