Laravel Imgur

Total Downloads Latest Stable Version License UnStable
Laravel-Imgur is super easy upload image to imgur package.

Installation

via composer

$ composer require yish/imgur

Registering

If you are using laravel 5.5 or later, you can use auto discovery, also, you don't need put in service provider to app.php.

Yish\Imgur\UploadServiceProvider::class,

Binding Facade

'Imgur' => Yish\Imgur\Facades\Upload::class,

Publishing config

$ php artisan vendor:publish

Usage

Imgur::upload($args);

Passing property $args can be url or file, for example, you can pass https://upload.wikimedia.org/wikipedia/commons/thumb/f/fa/Apple_logo_black.svg/1200px-Apple_logo_black.svg.png or passing file, notice should be instance of Illuminate\Http\UploadedFile.

Customize

You can customize headers or form properties:

Imgur::setHeaders([
    'headers' => [
        'authorization' => 'Client-ID ' . env('IMGUR_CLIENT_ID'),
        'content-type' => 'application/x-www-form-urlencoded',
    ]
])->setFormParams([
    'form_params' => [
        'image' => $image,
    ]
])->upload($image);

Retrieve data

You can use methods retrieve callback data.

$image = Imgur::upload($file);

// Get imgur image link.
$image->link(); //"https://i.imgur.com/XN9m1nW.jpg"

// Get imgur image file size.
$image->fileszie(); //43180

// Get imgur image file type.
$image->type(); //"image/jpeg"

// Get imgur image width.
$image->width(); //480

// Get imgur image height.
$image->height(); //640

// Or you can get usual data.
$image->usual();

//[
//  'link' => "https://i.imgur.com/XN9m1nW.jpg",
//  'filesize' => 43180,
//  'type' => "image/jpeg",
//  'width' => 480,
//  'height' => 640,
//]

Sometimes, you can get more data size, using size get more thumbbnail.


$image = Imgur::upload($file);

// Support: https://api.imgur.com/models/image

// Get small square.
$small_square = Imgur::size($image->link(), 's');

// Get big square thumbbnail.
$small_square = Imgur::size($image->link(), 'b');

// Get small small thumbbnail.
$small_square = Imgur::size($image->link(), 't');

// Get small medium thumbbnail.
$small_square = Imgur::size($image->link(), 'm');

// Get small large thumbbnail.
$small_square = Imgur::size($image->link(), 'l');

// Get small huge thumbbnail.
$small_square = Imgur::size($image->link(), 'h');
Last Updated: 1/27/2019, 1:25:04 PM