php-phantomjs使用php截图,laravel 5.6报错

laravel 5.6报错解决办法:

方法1、把laravel 5.6改成laravel5.5;
把composer.json里面的laravel 5.6改成 5.5版本,然后删除vendor,目录,运行composer install,注意这个做好备份,这个我没有测试过。
方法2、一条道走到底,运行composer update升级所有包及其依赖,然后再按照文档说的,进行安装ptantomjs包即可,我是使用的这种方式,经测试,是可以的。

Introduction

PHP PhantomJS is a flexible PHP library to load pages through the PhantomJS headless browser and return the page response. It is handy for testing websites that demand javascript support and also supports screen captures and PDF output.

Feature List

Load webpages through the PhantomJS headless browser
View detailed response data including page content, headers, status code etc.
Handle redirects
View javascript console errors
View detailed PhantomJS debuged information
Save screen captures to local disk
Output web pages to PDF document
Set viewport size
Set fixed header and footer for PDF output
Define screen capture x, y, width and height parameters
Delay page rendering for a specified time
Delay page rendering until page resources are fully loaded
Execute PhantomJS with command line options
Easily build and run custom PhantomJS scripts
Prerequisites
PHP PhantomJS requires PHP 5.4.0 or greater to run.

Installation

It is recommended that you use Composer to install PHP PhantomJS. First, add the following to your project’s composer.json file:

#composer.json

"scripts": {
    "post-install-cmd": [
        "PhantomInstaller\\Installer::installPhantomJS"
    ],
    "post-update-cmd": [
        "PhantomInstaller\\Installer::installPhantomJS"
    ]
}

This will ensure the latest version of PhantomJS is installed for your system, in your bin folder. If you haven’t defined your bin folder in your composer.json, add the path:

#composer.json

"config": {
    "bin-dir": "bin"
}

Finally, install PHP PhantomJS from the root of your project:

#bash

$ composer require "jonnyw/php-phantomjs:4.*"

If you would like to use another installation method or would like to see more detailed installation instructions, see the installation documentation.

Important

By default the PhantomJS library will look for the PhantomJS executable in the bin folder relative to where your script is running ~/bin/phantomjs. If the executable cannot be found or if the path to your PhantomJS executable differs from the default location, for example you have installed PhantomJS globally, you will need to define the path to your PhantomJS executable manually.

$client->getEngine()->setPath(’/path/to/phantomjs’);

Basic Usage

The following illustrates how to make a basic GET request and output the page content:


<?php

use JonnyW\PhantomJs\Client;

$client = Client::getInstance();

/** 
 * @see JonnyW\PhantomJs\Http\Request
 **/
$request = $client->getMessageFactory()->createRequest('http://jonnyw.me', 'GET');

/** 
 * @see JonnyW\PhantomJs\Http\Response 
 **/
$response = $client->getMessageFactory()->createResponse();

// Send the request
$client->send($request, $response);

if($response->getStatus() === 200) {

    // Dump the requested page content
    echo $response->getContent();
}

Saving a screen capture to local disk:

<?php

use JonnyW\PhantomJs\Client;

$client = Client::getInstance();

$width  = 800;
$height = 600;
$top    = 0;
$left   = 0;

/** 
 * @see JonnyW\PhantomJs\Http\CaptureRequest
 **/
$request = $client->getMessageFactory()->createCaptureRequest('http://jonnyw.me', 'GET');
$request->setOutputFile('/path/to/save/capture/file.jpg');
$request->setViewportSize($width, $height);
$request->setCaptureDimensions($width, $height, $top, $left);

/** 
 * @see JonnyW\PhantomJs\Http\Response 
 **/
$response = $client->getMessageFactory()->createResponse();

// Send the request
$client->send($request, $response);

Outputting a page as PDF:


<?php

use JonnyW\PhantomJs\Client;

$client = Client::getInstance();

/** 
 * @see JonnyW\PhantomJs\Http\PdfRequest
 **/
$request = $client->getMessageFactory()->createPdfRequest('http://jonnyw.me', 'GET');
$request->setOutputFile('/path/to/save/pdf/document.pdf');
$request->setFormat('A4');
$request->setOrientation('landscape');
$request->setMargin('1cm');

/** 
 * @see JonnyW\PhantomJs\Http\Response 
 **/
$response = $client->getMessageFactory()->createResponse();

// Send the request
$client->send($request, $response);

<?php

use JonnyW\PhantomJs\Client;

$client = Client::getInstance();

/** 
 * @see JonnyW\PhantomJs\Http\PdfRequest
 **/
$request = $client->getMessageFactory()->createPdfRequest('http://jonnyw.me', 'GET');
$request->setOutputFile('/path/to/save/pdf/document.pdf');
$request->setFormat('A4');
$request->setOrientation('landscape');
$request->setMargin('1cm');

/** 
 * @see JonnyW\PhantomJs\Http\Response 
 **/
$response = $client->getMessageFactory()->createResponse();

// Send the request
$client->send($request, $response);

原文:http://jonnnnyw.github.io/php-phantomjs/
本来准备翻译一下的,但是一看,写程序的基本都能看懂,就转过来算了。

记得指定phantomjs执行文件的绝对路径
另外,在laravel 5.6里面使用会遇到问题,会遇到一大堆报错,大概意思symfony的两个包冲突了。

 symfony/dependency-injection 2.6.x-dev conflicts with symfony/console[v4.1.0].

解决办法当时没记录,忘记了,后面碰到了再记录.

这里写图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

SHUIPING_YANG

你的鼓励是我创作的最大动力。

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值