Website screenshots

前端 未结 26 3471
长发绾君心
长发绾君心 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 07:02

    I wrote a quick and dirty app the other day for doing this using Google API. Most certainly scope for improvement...

    • It uses the latest Google API ver 5.
    • Image size now 500px wide
    • Supports desktop & mobile view
    • Save to a file in a specified folder
    • Incorporate a rudimentary cache system

    Find it here with a live demo and code.

    I did not post the code here simply because I keep on refining it and hopefully when I have time, convert it into a proper class.

    0 讨论(0)
  • 2020-11-21 07:03

    I always use microweber screen to capture screenshot of any webpage. Here we can find a well written tutorial. This is easier and should not take more than 3 minutes to learn.

    0 讨论(0)
  • 2020-11-21 07:03

    you can use cutycapt .

    kwhtml is deprecated and show page like old browser.

    0 讨论(0)
  • 2020-11-21 07:05

    Well, PhantomJS is a browser that can be easily put on a server and integrate it to php. You can find the code in WDudes. They have included lot more features like specifying the image size, cache, download as a file or display in img src etc.

    <img src=”screenshot.php?url=google.com” />
    

    URL Parameters

    • Width and Height: screenshot.php?url=google.com&w=1000&h=800

    • With cropping: screenshot.php?url=google.com&w=1000&h=800&clipw=800&cliph=600

    • Disable cache and load fresh screesnhot:
      screenshot.php?url=google.com&cache=0

    • To download the image: screenshot.php?url=google.com&download=true

    You can see the tutorial here: Capture Screenshot of a Website using PHP without API

    0 讨论(0)
  • 2020-11-21 07:07

    You can use simple headless browser like PhantomJS to grab the page.

    Also you can use PhantomJS with PHP.

    Check out this little php script that do this. Take a look here https://github.com/microweber/screen

    And here is the API- http://screen.microweber.com/shot.php?url=https://stackoverflow.com/questions/757675/website-screenshots-using-php

    0 讨论(0)
  • 2020-11-21 07:09

    You can use https://grabz.it solution.

    It's got a PHP API which is very flexible and can be called in different ways such as from a cronjob or a PHP web page.

    In order to implement it you will need to first get an app key and secret and download the (free) SDK.

    And an example for implementation. First of all initialization:

    include("GrabzItClient.class.php");
    
    // Create the GrabzItClient class
    // Replace "APPLICATION KEY", "APPLICATION SECRET" with the values from your account!
    $grabzIt = new GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret");
    

    And screenshoting example:

    // To take a image screenshot
    $grabzIt->URLToImage("http://www.google.com");  
    // Or to take a PDF screenshot
    $grabzIt->URLToPDF("http://www.google.com");
    // Or to convert online videos into animated GIF's
    $grabzIt->URLToAnimation("http://www.example.com/video.avi");
    // Or to capture table(s)
    $grabzIt->URLToTable("http://www.google.com");
    

    Next is the saving.You can use one of the two save methods, Save if publicly accessible callback handle available and SaveTo if not. Check the documentation for details.

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