Code Monkey home page Code Monkey logo

screeenlyclient's Introduction

ScreenlyClient

Build Status
Latest Stable Version Total Downloads Latest Unstable Version License

PHP Wrapper for the Screeenly API. You must have a Screeenly account to use this package.

Important notice: This package has been abandoned! I want to focus on more useful projects and the screeenly API is already very easy to use.

Installation

Install the package with composer:

Guzzle v6:

$ composer require "wnx/screeenly-client:~2.0"

Guzzle v5:

$ composer require "wnx/screeenly-client:~1.0"

For Laravel 4 prjoects:

$ composer require "wnx/screeenly-client:~0.3"

Usage

Laravel 5

Read more for Laravel 4 usage.

Add the following code to your providers array in app/conifg/app.php:

...

'Wnx\ScreeenlyClient\ScreeenlyClientServiceProvider',

Publish the configration file and add your Screeenly API Key in config/screeenly_client.php.

php artisan vendor:publish --provider="Wnx\ScreeenlyClient\ScreeenlyClientServiceProvider"

Now you have access to the Screenshot Facade. Use it like the example below:

$path       = public_path('/');
$screenshot = Screenshot::capture('http://google.com');
$localPath  = $screenshot->store($path, 'screenshot.jpg');

Non-Laravel Usage

use Wnx\ScreeenlyClient\Screenshot;
...

$screenshot = new Screenshot($key);
$screenshot->capture('http://google.com');
$localPath = $screenshot->store('path/to/image/store/', 'screenshot.jpg');

Available Methods

$screeenshot->capture($url);

Create Screenshot of given URL.

$screeenshot->store($path, $filename);

Store screenshot on local disk. Returns path to image.

$screeenshot->setHeight(integer);

Optional. Set screenshot height.

$screeenshot->setWidth(integer);

Optional. Set screenshot width.

$screeenshot->getPath();

Return path to temporary image on Screeenly server.

$screeenshot->getBase64();

Return base64-string for screenshot.

License

MIT

screeenlyclient's People

Contributors

stefanzweifel avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

screeenlyclient's Issues

Error config_path() in lumen

I've error in boot() in service provider because lumen don't have config_path(). Because of it I need to comment that method

ClientException in Middleware.php line 69: Client error: 429

Hello @stefanzweifel ! How are you doing?

Yesterday I migrated my website from a shared hosting to a vps. But know, I can't store the screenshot anymore. Bellow my code and the error. I searched on the internet but coudn't find anything related to my problem... I tested and I can create the screenshot. The problem is after creating when I am trying to store it!

My code:

$hash = Str::random(5);
$website_to_screenshot = $request->input('hewit');
$screenshot_name = $hash.'.jpg';
$preview_path = 'http://hew.to/previews/guests/'.$hash.'.jpg';
$hewed = 'http://hew.to/'. $hash;

$screenshot = new Screenshot('SECRET-API-KEY');
$screenshot->capture($website_to_screenshot);

Error:

    in Middleware.php line 69
    at Middleware::GuzzleHttp\{closure}(object(Response)) in Promise.php line 199
    at Promise::callHandler('1', object(Response), array(object(Promise), object(Closure), null)) in Promise.php line 152
    at Promise::GuzzleHttp\Promise\{closure}() in TaskQueue.php line 60
    at TaskQueue->run() in CurlMultiHandler.php line 96
    at CurlMultiHandler->tick() in CurlMultiHandler.php line 123
    at CurlMultiHandler->execute(true) in Promise.php line 240
    at Promise->invokeWaitFn() in Promise.php line 217
    at Promise->waitIfPending() in Promise.php line 261
    at Promise->invokeWaitList() in Promise.php line 219
    at Promise->waitIfPending() in Promise.php line 62
    at Promise->wait() in Client.php line 130
    at Client->request('post', 'http://screeenly.com/api/v1/fullsize', array('form_params' => array('key' => 'SECRET-API-KEY', 'url' => 'https://murze.be/about-me/', 'width' => '1024', 'height' => null))) in Client.php line 88
    at Client->__call('post', array('http://screeenly.com/api/v1/fullsize', array('form_params' => array('key' => 'SECRET-API-KEY', 'url' => 'https://murze.be/about-me/', 'width' => '1024', 'height' => null)))) in Screenshot.php line 80
    at Client->post('http://screeenly.com/api/v1/fullsize', array('form_params' => array('key' => 'SECRET-API-KEY', 'url' => 'https://murze.be/about-me/', 'width' => '1024', 'height' => null))) in Screenshot.php line 80
    at Screenshot->capture('https://murze.be/about-me/') in LinksController.php line 86
    at LinksController->create(object(Request))
    at call_user_func_array(array(object(LinksController), 'create'), array(object(Request))) in Controller.php line 256
    at Controller->callAction('create', array(object(Request))) in ControllerDispatcher.php line 164
    at ControllerDispatcher->call(object(LinksController), object(Route), 'create') in ControllerDispatcher.php line 112
    at ControllerDispatcher->Illuminate\Routing\{closure}(object(Request))
    at call_user_func(object(Closure), object(Request)) in Pipeline.php line 139
    at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
    at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
    at Pipeline->then(object(Closure)) in ControllerDispatcher.php line 114
    at ControllerDispatcher->callWithinStack(object(LinksController), object(Route), object(Request), 'create') in ControllerDispatcher.php line 69
    at ControllerDispatcher->dispatch(object(Route), object(Request), 'App\Http\Controllers\LinksController', 'create') in Route.php line 201
    at Route->runWithCustomDispatcher(object(Request)) in Route.php line 134
    at Route->run(object(Request)) in Router.php line 704
    at Router->Illuminate\Routing\{closure}(object(Request))
    at call_user_func(object(Closure), object(Request)) in Pipeline.php line 139
    at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
    at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
    at Pipeline->then(object(Closure)) in Router.php line 706
    at Router->runRouteWithinStack(object(Route), object(Request)) in Router.php line 671
    at Router->dispatchToRoute(object(Request)) in Router.php line 631
    at Router->dispatch(object(Request)) in Kernel.php line 236
    at Kernel->Illuminate\Foundation\Http\{closure}(object(Request))
    at call_user_func(object(Closure), object(Request)) in Pipeline.php line 139
    at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in VerifyCsrfToken.php line 50
    at VerifyCsrfToken->handle(object(Request), object(Closure))
    at call_user_func_array(array(object(VerifyCsrfToken), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
    at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in ShareErrorsFromSession.php line 54
    at ShareErrorsFromSession->handle(object(Request), object(Closure))
    at call_user_func_array(array(object(ShareErrorsFromSession), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
    at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in StartSession.php line 62
    at StartSession->handle(object(Request), object(Closure))
    at call_user_func_array(array(object(StartSession), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
    at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in AddQueuedCookiesToResponse.php line 37
    at AddQueuedCookiesToResponse->handle(object(Request), object(Closure))
    at call_user_func_array(array(object(AddQueuedCookiesToResponse), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
    at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in EncryptCookies.php line 59
    at EncryptCookies->handle(object(Request), object(Closure))
    at call_user_func_array(array(object(EncryptCookies), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
    at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in CheckForMaintenanceMode.php line 42
    at CheckForMaintenanceMode->handle(object(Request), object(Closure))
    at call_user_func_array(array(object(CheckForMaintenanceMode), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
    at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
    at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
    at Pipeline->then(object(Closure)) in Kernel.php line 122
    at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 87
    at Kernel->handle(object(Request)) in index.php line 54

Bad Request with v1

Hey,

this is an awesome project :)

I've tried v1 of the client, since I can't have guzzle v6 in my deps.
I also created an account on screenly.com
However, the client always gives me a 400 Bad Request. Any tips?

Guzzle 6?

Hi - thanks for creating this package! Do you have any plans to support Guzzle 6.0?

InvalidArgumentException in Client.php

Hi, with this new release I experienced this error in Laravel 5.1:
InvalidArgumentException in Client.php line 387:
"Passing in the "body" request option as an array to send a POST request has been deprecated. Please use the "form_params" request option to send a application/x-www-form-urlencoded request, or a the "multipart" request option to send a multipart/form-data request."
In last version I've never used a form to send this request.
How can it be fixed?

Improvements aka v2.1

This issue is just a bag of some improvements / features I would like to add in the future

  • Abort API Request if no or an invalid URL is given
  • Improve Error Handling (Throw a readable exception instead of just Clienterror 400)
  • Improve / Add Tests
  • Improve overall code quality

Request: Change the apiUrl

Hey I love this plugin and love Screeenly! To reduce load on your server(s) I created my own hosted version of Screeenly, but I can not change the apiUrl (Screenshot.php, line 53: protected $apiUrl = 'http://screeenly.com/api/v1/fullsize';)

Can you build it so that I can change it with out demolishing the vendor-folder/ Screenshot.php?

Thnx again!

ClientException in Middleware.php

Sorry if I bother you again, I updated to: wnx/screeenly-client (v2.0.1)
Now I get another error while image is processing.

ClientException in Middleware.php line 69:
Client error: 400

snapshots_error

[InvalidArgumentException] Could not find package wnx/screeenly-client~2.0 at any version for your m inimum-stability (stable). Check the package spelling or your minimum-sta bility

Hello there! I tested your app in your site and it's just what I need!

Thanks for creating such a usefull app...

I tried to install it (I am using Laravel Framework version 5.1.15 (LTS)), but I get this error:

[InvalidArgumentException]
  Could not find package wnx/screeenly-client~2.0 at any version for your m
  inimum-stability (stable). Check the package spelling or your minimum-sta
  bility

What should I do to install your package?

Javascript on webpages

If a website fx uses javascript to render something it is not displayed on the screenshot. If it is possible to parse a wait-before-taking-a-screenshot-in-milisecords-parameter to the API and the API waits 1 second before taking the screenshot, the page would be loaded. Or the script could wait for the page to finish loading

width and height

setWidth and setHeight are not working for me

I capture a screenshot of a pretty long webpage (13000px height) so i user the following code to crop it

$screenshot = Screenshot::capture($url);
$screenshot->setWidth(1024);
$screenshot->setHeight(800);
$screenshot->store($path); 

the stored image has the same dimensions as the original webpage ..
Am i doing something wrong here ?

Taking a screenshot within a Queued Job do not work

@stefanzweifel Good night!

I was using your package inside a Controller. And I decided to use it inside a Queued Job.

I am using the same code, but it does not work at all... The Job is fired (I can see it in the database-> jobs table) but the screenshot is never taken. I am sure that this is very trivial, but if you could help me, I would appreciate.

LinksController.php

$hash = Str::random(5);
            $website_to_screenshot = $request->input('hewit');
            $screenshot_name = $hash.'.jpg';
            $preview_path = 'http://hew.to/previews/guests/'.$hash.'.jpg';
            $hewed = 'http://hew.to/'. $hash;

            $job = (new CreateScreenshotPreview($website_to_screenshot, $screenshot_name))->delay(5);
            $this->dispatch($job);

            $link = Link::create([

                'url'           => $request->input('hewit'),
                'hash'          => $hash,
                'preview_path'  => $preview_path,

            ]);

            return Redirect::home()->with([
                'hewed'       => $hewed,
                'hash'        => $hash,
            ]);

CreateScreenshotPreview.php (app/Jobs/CreateScreenshotPreview.php)

<?php

namespace App\Jobs;

use App\Jobs\Job;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Bus\SelfHandling;
use Illuminate\Contracts\Queue\ShouldQueue;
use Wnx\ScreeenlyClient\Screenshot;

class CreateScreenshotPreview extends Job implements SelfHandling, ShouldQueue
{
    use InteractsWithQueue, SerializesModels;

    protected $website_to_screenshot;
    protected $screenshot_name;

    public function __construct($website_to_screenshot, $screenshot_name)
    {
        $this->website_to_screenshot = $website_to_screenshot;
        $this->screenshot_name = $screenshot_name;
    }

    public function handle()
    {
        $screenshot = new Screenshot('API_KEY');
        $screenshot->capture($this->website_to_screenshot);
        $screenshot->store('/home/frgcplql/public_html/hew.to/public/previews/guests/', $this->screenshot_name);

    }
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.