Website screenshots

2018-12-31 01:06发布

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

22条回答
姐姐魅力值爆表
2楼-- · 2018-12-31 01:11

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

查看更多
牵手、夕阳
3楼-- · 2018-12-31 01:12

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.

查看更多
高级女魔头
4楼-- · 2018-12-31 01:13

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

查看更多
孤独总比滥情好
5楼-- · 2018-12-31 01:15

I'm on Windows so I was able to use the imagegrabwindow function after reading the tip on here from stephan. I added in cropping (to get rid of the Browser header, scroll bars, etc.) and resizing to get a final image. Here's my code. Hope that helps someone.

查看更多
明月照影归
6楼-- · 2018-12-31 01:16

you can use cutycapt .

kwhtml is deprecated and show page like old browser.

查看更多
梦寄多情
7楼-- · 2018-12-31 01:16

I've found this to be the best and easiest tool around: ScreenShotMachine. It's a paid service, but you get 100 free screenshots and you can buy another 2,000 for (about) $20, so it's a pretty good deal. It has a very simple usage, you just use a URL, so I wrote this little script to save a file based on it:

<?php
  $url = file_get_contents("http://api.screenshotmachine.com/?key={mykey}&url=https://stackoverflow.com&size=X");

  $file = fopen("snapshots/stack.jpg", "w+");
  fwrite($file, $url);
  fclose($file);
  die("saved file!");
?>

They have a very good documentation here, so you should definitely take a look.

查看更多
登录 后发表回答