PHP code example of tommy-dai / screenshot

1. Go to this page and download the library: Download tommy-dai/screenshot library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

tommy-dai / screenshot example snippets


$screenshot = new \Screenshot\ScreenShot();
$screenshot->shot('http://image.baidu.com');

//截图服务端口号
port = 8181;

//超时时间(毫秒)
timeOut = 5000;

//是否解析页面中的JavaScript代码
javascriptEnabled = false;

//图片宽度(单位像素)
width = 750;

//图片高度(单位像素)
height = 1334;

//截图日志文件存放路径(绝对路径)
logPath = '';

//获取默认配置
$config = new \Screenshot\Config();

//修改默认端口号(修改配置)
$config->setPort(8080);

//修改默认端图片宽度
$config->setWidth(600);

//修改默认端图片高度
$config->setHeight(800);

//开启JavaScript支持(开启后将可以解析页面中js代码,对于js生成的页面可以截取)
$config->setJavascriptEnabled(true);

//用配置文件初始化截图服务(不传$config会走默认配置)
$screenshot = new \Screenshot\ScreenShot($config);

//生成截图服务并截取百度图片
$screenshot->shot('http://image.baidu.com');

$screenshot = new \Screenshot\ScreenShot();

//关闭截图服务
$screenshot->stop();

$screenshot = new \Screenshot\ScreenShot();

//返回base64的图片,可用于本地保存
$screenshot->getShot();

$screenshot = new \Screenshot\ScreenShot();

//开启截图服务
$screenshot->start();