Created
April 13, 2018 14:07
-
-
Save theqwan-chengwei/d2270b69b481de73eccb662fe89178e5 to your computer and use it in GitHub Desktop.
use php-phantomjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$client = Client::getInstance(); | |
$client->getEngine()->setPath('/bin/phantomjs'); | |
// $client->getEngine()->addOption('--ignore-ssl-errors=true'); | |
$client->getEngine()->addOption('--ssl-protocol=any'); | |
$client->getEngine()->addOption('--web-security=false'); | |
$client->getEngine()->debug(true); | |
$request = $client->getMessageFactory()->createCaptureRequest(); | |
$response = $client->getMessageFactory()->createResponse(); | |
$width = 800; | |
$height = 800; | |
$captureFile = public_path("images/screenshots/{$bookmark->id}.png"); | |
$thumbFile = public_path("images/screenshots/{$bookmark->id}_thumb.png"); | |
$request->setMethod('GET'); | |
$request->setUrl($bookmark->url); | |
$request->setOutputFile($captureFile); | |
$request->setCaptureDimensions($width, $height); | |
$request->setViewportSize($width, $height); | |
$timeout = 20000; // 20 seconds | |
$request->setTimeout($timeout); | |
$client->send($request, $response); | |
$status = $response->getStatus(); | |
if ($status === 200 || $status === 301 || $status === 302) { | |
$img = Image::make($captureFile); | |
$img->widen(300)->crop(300, 160, 0, 0); | |
$img->save($thumbFile); | |
$bookmark->thumbnail = 1; | |
$bookmark->save(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment