snappyimg/snappyimg-php

Scale, crop and optimize images on-the-fly,

v1.0 2018-09-20 15:46 UTC

This package is auto-updated.

Last update: 2024-10-12 05:47:53 UTC


README

Build Status

This is a PHP implementation of Snappyimg URL builder. For more information about the service, go to https://www.snappyimg.com/.

Installation

This library is available as Composer package:

$ composer require snappyimg/snappyimg-php

Demo

Processed original image https://www.snappyimg.com/demo.jpg into 640×360: https://serve.snappyimg.com/snappyimg/pvvJK7Di3E1Fjetx9viameQMNo0LjHcM2rUh8v10En0/fit/640/360/ce/1/aHR0cHM6Ly93d3cuc25hcHB5aW1nLmNvbS9kZW1vLmpwZw.jpg

Example usage

$snappy = new Snappyimg($appToken, $appSecret, Snappyimg::STAGE_DEMO);

$options = Options::fromDefaults(360, 420);
$url = $snappy->buildUrl($options, 'https://www.snappyimg.com/demo.jpg');

Where $appToken and $appSecret are generated for you when you register at snappyimg.com.

<img alt="Snappyimg Example" src="{{$url}}">

While STAGE_DEMO is available for free for all users, you will need a subscription to use STAGE_SERVE.

Additional options

The Options class lets you specify exactly how the image should be processed.

$options = Options::fromDefaults(360, 420)
    ->setResize(Snappyimg::RESIZE_FIT)
    ->setGravity(Snappyimg::GRAVITY_SMART)
    ->setEnlarge(FALSE)
    ->setFormat(Snappyimg::FORMAT_WEBP);

The options themselves are explained at Documentation and at each method.