Is there any way of taking a screenshot of a website in PHP, then saving it to a file?
I wrote a quick and dirty app the other day for doing this using Google API. Most certainly scope for improvement...
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.
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.
you can use cutycapt .
kwhtml is deprecated and show page like old browser.
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
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
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.