Website screenshots

前端 未结 26 3476
长发绾君心
长发绾君心 2020-11-21 06:07

Is there any way of taking a screenshot of a website in PHP, then saving it to a file?

相关标签:
26条回答
  • 2020-11-21 06:51

    cutycapt saves webpages to most image formats(jpg,png..) download it from your synaptic, it works much better than wkhtmltopdf

    0 讨论(0)
  • 2020-11-21 06:51

    It all depends on how you wish to take the screenshot.

    You could do this via PHP, using a webservice to get the image for you

    grabz.it has a webservice to do just this, here's an article showing a simple example of using the service.

    http://www.phpbuilder.com/articles/news-reviews/miscellaneous/capture-screenshots-in-php-with-grabzit-120524022959.html

    0 讨论(0)
  • 2020-11-21 06:52

    Yes it is. If you only need image of URL try this

    <img src='http://zenithwebtechnologies.com.au/thumbnail.php?url=www.subway.com.au'>
    

    Pass the url as argument and you'll get the image for more details check this link http://zenithwebtechnologies.com.au/auto-thumbnail-generation-from-url.html

    0 讨论(0)
  • 2020-11-21 06:52

    There is a lot of options and they all have their pros and cons. Here is list of options ordered by implementation difficulty.

    Option 1: Use an API (the easiest)

    • ApiFlash (based on chrome)
    • EvoPDF (has an option for html)
    • Grabzit
    • ...

    Pros

    • Execute Javascript
    • Near perfect rendering
    • Fast when caching options are correctly used
    • Scale is handled by the APIs
    • Precise timing, viewport, ...
    • Most of the time they offer a free plan

    Cons

    • Not free if you plan to use them a lot

    Option 2: Use one of the many available libraries

    • dom-to-image
    • wkhtmltoimage (included in the wkhtmltopdf tool)
    • phpwkhtmltopdf
    • ...

    Pros

    • Conversion is quite fast most of the time

    Cons

    • Bad rendering
    • Does not execute javascript
    • No support for recent web features (FlexBox, Advanced Selectors, Webfonts, Box Sizing, Media Queries, HTML5 tags...)
    • Sometimes not so easy to install
    • Complicated to scale

    Option 3: Use PhantomJs and maybe a wrapper library

    • PhantomJs
    • php-phantomjs (php wrapper library for PhantomJs)
    • ...

    Pros

    • Execute Javascript
    • Quite fast

    Cons

    • Bad rendering
    • PhantomJs has been deprecated and is not maintained anymore.
    • No support for recent web features (FlexBox, Advanced Selectors, Webfonts, Box Sizing, Media Queries, HTML5 tags...)
    • Complicated to scale
    • Not so easy to make it work if there is images to be loaded ...

    Option 4: Use Chrome Headless and maybe a wrapper library

    • Chrome Headless
    • chrome-devtools-protocol
    • puphpeteer
    • ...

    Pros

    • Execute Javascript
    • Near perfect rendering

    Cons

    • Not so easy to have exactly the wanted result regarding:
      • page load timing
      • proxy integration
      • auto scrolling
      • ...
    • Complicated to scale
    • Quite slow and even slower if the html contains external links

    Disclaimer: I'm the founder of ApiFlash. I did my best to provide an honest and useful answer.

    0 讨论(0)
  • 2020-11-21 06:54

    This ought to be good for you:

    https://wkhtmltopdf.org/

    Make sure you download the wkhtmltoimage distribution!

    0 讨论(0)
  • 2020-11-21 06:54

    It's in Python, but going over the documentation and code you can see exactly how this is done. If you can run python, then it's a ready-made solution for you:

    http://browsershots.org/

    Note that everything can run on one machine for one platform, or one machine with virtual machines running the other platforms.

    Free, open source, scroll to bottom of page for links to documentation, source code, and other information.

    0 讨论(0)
提交回复
热议问题