Guest User

Untitled

a guest
Apr 21st, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. $client = Client::getInstance();
  2.  
  3. $client->getEngine()->setPath('/bin/phantomjs');
  4. // $client->getEngine()->addOption('--ignore-ssl-errors=true');
  5. $client->getEngine()->addOption('--ssl-protocol=any');
  6. $client->getEngine()->addOption('--web-security=false');
  7. $client->getEngine()->debug(true);
  8.  
  9. $request = $client->getMessageFactory()->createCaptureRequest();
  10. $response = $client->getMessageFactory()->createResponse();
  11.  
  12. $width = 800;
  13. $height = 800;
  14. $captureFile = public_path("images/screenshots/{$bookmark->id}.png");
  15. $thumbFile = public_path("images/screenshots/{$bookmark->id}_thumb.png");
  16.  
  17. $request->setMethod('GET');
  18. $request->setUrl($bookmark->url);
  19. $request->setOutputFile($captureFile);
  20. $request->setCaptureDimensions($width, $height);
  21. $request->setViewportSize($width, $height);
  22.  
  23. $timeout = 20000; // 20 seconds
  24. $request->setTimeout($timeout);
  25.  
  26. $client->send($request, $response);
  27.  
  28. $status = $response->getStatus();
  29.  
  30. if ($status === 200 || $status === 301 || $status === 302) {
  31. $img = Image::make($captureFile);
  32. $img->widen(300)->crop(300, 160, 0, 0);
  33. $img->save($thumbFile);
  34.  
  35. $bookmark->thumbnail = 1;
  36. $bookmark->save();
  37. }
Add Comment
Please, Sign In to add comment