Website screenshots

前端 未结 26 3533
长发绾君心
长发绾君心 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: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.

提交回复
热议问题