davidcb/laravel-shortpixel

Laravel 5+ package for ShortPixel API integration

Downloads

8905

Stars

5

Version

0.3.2

Laravel-Shortpixel

Laravel 5+ wrapper for ShortPixel API

Installation

Install via Composer:

composer require davidcb/laravel-shortpixel

If you're using Laravel >= 5.5, you can skip this as this package will be auto-discovered. Add the service provider to config/app.php

Davidcb\LaravelShortPixel\LaravelShortPixelServiceProvider::class,

You can register the facade in the aliases array in the config/app.php file

'LaravelShortPixel' => Davidcb\LaravelShortPixel\Facades\Esendex::class,

Publish the config file

$ php artisan vendor:publish --provider="Davidcb\LaravelShortPixel\LaravelShortPixelServiceProvider"

Set your API key on your .env file

SHORT_PIXEL_API_KEY=secret

Usage

You can find all the methods in the original short-pixel-optimizer/shortpixel-php package.

Examples:

// From URL
$result = LaravelShortPixel::fromUrls('https://your.site/img/unoptimized.png', '/path/to/save/to'[, 'filename.png', $compression_level = 1, $width = 200, $height = 200, $maxDimension = true]);
// From file
$result = LaravelShortPixel::fromFiles('/path/to/your/local/unoptimized.png', '/path/to/save/to'[, $compression_level = 1, $width = 200, $height = 200, $maxDimension = true]);
// From files
$result = LaravelShortPixel::fromFiles(array('/path/to/your/local/unoptimized.png', '/path/to/your/local/unoptimized2.png'), '/path/to/save/to'[, $compression_level = 1, $width = 200, $height = 200, $maxDimension = true]);
// From folder
$result = LaravelShortPixel::fromFolder('/path/to/your/local/folder', '/path/to/save/to'[, $compression_level = 1, $width = 200, $height = 200, $maxDimension = true]);

The compression_level, width, height and maxDimension are optional. Compression levels are 0 - loseless, 1 - lossy, 2- glossy. Default compression level for your images is set on the configuration file (lossy is set as default).

davidcb

Author

davidcb