Skip to content
PHP Library for assembling Snappyimg URLs.
PHP Shell
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src/Snappyimg
tests
.gitignore
.travis.yml
LICENSE
README.md
composer.json
logo.png

README.md

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.

You can’t perform that action at this time.