Convert URL to screenshot (script)

前端 未结 6 1668
深忆病人
深忆病人 2020-12-15 13:19

There is the URL of page on the Internet. I need to get a screenshot of this page (no matter in which browser).

I need a script (PHP, Python (even Django framework)

6条回答
  •  醉话见心
    2020-12-15 13:48

    Solution using Google Page Speed - tested & working.

    //SOLUTION 1
    
    ";
    echo $show_link;
    
    //SOLUTION 2
    
    $name = 'test';
    $googlePagespeedData = file_get_contents("https://www.googleapis.com/pagespeedonline/v2/runPagespeed?url=$link&screenshot=true");
    $googlePagespeedData = json_decode($googlePagespeedData, true);
    $screenshot = base64_decode($googlePagespeedData['screenshot']['data']);
    $data = str_replace('_','/',$googlePagespeedData['screenshot']['data']);
    $data = str_replace('-','+',$data);
    $decoded = base64_decode($data);
    file_put_contents('myfolder/'.$name.'.jpg',$decoded);
    $file_name = "$name.jpg";
    
    /*
    -- IMPORTANT INFORMATION -- READ BELOW --
    
    Choose how to proceed!
    1. Use the above to display screenshots of links = longer processing time for multiple links.
    2. Save image to a file, reference the saved image = more disk space needed if multiple links.
    
    Note the trade off between processing time and disk space, if you're on a shared hosting platform with a small disk space limit and envisage or already have a lot of users (forums beware) you may want to consider a bigger hosting plan or even a dedicated server.
    
    */
    ?>
    

提交回复
热议问题