2017 © Pedro Peláez
 

library image-manager

A PHP 5.4 library to control dynamic image assets in a cloud environment

image

bravo3/image-manager

A PHP 5.4 library to control dynamic image assets in a cloud environment

  • Wednesday, January 27, 2016
  • by jordonsc
  • Repository
  • 8 Watchers
  • 16 Stars
  • 8,114 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 6 Forks
  • 1 Open issues
  • 24 Versions
  • 0 % Grown

The README.md

Image Manager

A PHP 5.4 image manager intended for cloud use. This image manager is designed to be low-level and work with 'keys' - not directly attach to an entity., (*1)

Features

  • Easily push and pull images to any remote filesystem (eg Amazon S3)
  • Request an image with specific dimensions - allow the manager to transparently create & store this variation
  • Request that an image dimension exists (will be created if it doesn't), allowing for the storage device to be used as a CDN end-point
  • Use a caching service to maintain a knowledge base of image dimensions available to improve performance
  • Load & save images from memory or a file
  • Convert image format & quality with ease
  • Customisable encoders
  • GD and Imagick support
  • PDF support (via Imagick)

Examples

Storing an image

// Use the local filesystem as a fake remote (replace with S3, etc)
$im = new ImageManager(new Filesystem(new LocalAdapter('/tmp/images')));

// Load local "image.png" and give it a key of 'content_123_image_1' (using the filename is suitable too)
$image = $im->loadFromFile('image.png', 'content_123_image_1');

// Save it on the remote
$im->push($image);

Retrieving an image

$image = new Image('content_123_image_1');
$im->pull($image);

// Save to local filesystem
$im->save($image, '/tmp/image.png');

// Output to client
echo $image->getData();

Retrieving an automatic variation

// Define a dimension that the image will fit in a height of 200px
$dimensions = new ImageDimensions(null, 200);

// Create a specification for a JPEG format, quality 75% and use the above dimensions
$image = new ImageVariation('content_123_image_1', ImageFormat::JPEG(), 75, $dimensions);

// Automatically create the variation when we pull
$im->pull($image);

if (!$im->isPersistent()) {
    // Make sure our new variation exists on the remote
    $im->push($image);
}

echo $image->getData();

Create a variation manually

$source = $im->loadFromFile('image.png', 'content_123_image_1');
$resized = $im->createVariation($source, ImageFormat::JPEG(), 90, new ImageDimensions(100, 100));
$im->push($resized);

Check if a variation exists

$image = new ImageVariation('content_123_image_1', ImageFormat::JPEG(), 75, $dimensions);

if (!$im->exists($image)) {
    $im->pull($image);  // Creates the variation
    $im->push($image);  // Save it on the remote
}

echo '<img src="http://cdn.example.com/'.$im->getKey().'" />';

Caching

Because remote storage services have a moderate degree of lag while talking to, it's probably not appropriate to do "exists" checks on every image variation during page generation. To avoid this you can either pre-render the image and assume it will exist, or using a quick caching mechanic to store an inventory of all images available., (*2)

Your caching mechanic MUST be persistent - if a cache key is lost the image manager will assume the remote file does not exist. Using a database or disk backed key/value storage is recommended (eg Redis)., (*3)

To use caching, just include a \Bravo3\Cache\PoolInterface implementation in the ImageManager's constructor., (*4)

Encoders

By default the image manager will use the InterventionEncoder (@see http://image.intervention.io/), which supports base image formats. You can switch this for the ImagickEncoder which also allows for PDF documents to be used as an input., (*5)

To add support for native Imagick, but use Intervention where possible (thus giving you PDF support):, (*6)

$im = new ImageManager(...);
$im->addEncoder(new ImagickEncoder());

To use only the Imagick encoder:, (*7)

$im = new ImageManager($filesystem, $cache_pool, [new ImagickEncoder()]);

Future Considerations

  • Allow for image manipulations (eg add text, rotate, etc)
  • Allow for customisable variation naming schemes

The Versions

27/01 2016

dev-master

9999999-dev

A PHP 5.4 library to control dynamic image assets in a cloud environment

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jordon Scott

aws image azure google cloud

27/01 2016

1.2.6

1.2.6.0

A PHP 5.4 library to control dynamic image assets in a cloud environment

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jordon Scott

aws image azure google cloud

27/01 2016

dev-feature/fix-tag-on-rename

dev-feature/fix-tag-on-rename

A PHP 5.4 library to control dynamic image assets in a cloud environment

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jordon Scott

aws image azure google cloud

08/12 2015

1.2.5

1.2.5.0

A PHP 5.4 library to control dynamic image assets in a cloud environment

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jordon Scott

aws image azure google cloud

11/11 2015

1.2.4

1.2.4.0

A PHP 5.4 library to control dynamic image assets in a cloud environment

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jordon Scott

aws image azure google cloud

31/08 2015

1.2.3

1.2.3.0

A PHP 5.4 library to control dynamic image assets in a cloud environment

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jordon Scott

aws image azure google cloud

26/08 2015

1.2.2

1.2.2.0

A PHP 5.4 library to control dynamic image assets in a cloud environment

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jordon Scott

aws image azure google cloud

05/05 2015

1.2.1

1.2.1.0

A PHP 5.4 library to control dynamic image assets in a cloud environment

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jordon Scott

aws image azure google cloud

21/04 2015

1.2.0

1.2.0.0

A PHP 5.4 library to control dynamic image assets in a cloud environment

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jordon Scott

aws image azure google cloud

07/04 2015

1.1.8

1.1.8.0

A PHP 5.4 library to control dynamic image assets in a cloud environment

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jordon Scott

aws image azure google cloud

31/03 2015

1.1.7

1.1.7.0

A PHP 5.4 library to control dynamic image assets in a cloud environment

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jordon Scott

aws image azure google cloud

30/03 2015

1.1.6

1.1.6.0

A PHP 5.4 library to control dynamic image assets in a cloud environment

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jordon Scott

aws image azure google cloud

04/03 2015

1.1.5

1.1.5.0

A PHP 5.4 library to control dynamic image assets in a cloud environment

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jordon Scott

aws image azure google cloud

13/02 2015

1.1.4

1.1.4.0

A PHP 5.4 library to control dynamic image assets in a cloud environment

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jordon Scott

aws image azure google cloud

29/01 2015

1.1.3

1.1.3.0

A PHP 5.4 library to control dynamic image assets in a cloud environment

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jordon Scott

aws image azure google cloud

28/01 2015

1.1.2

1.1.2.0

A PHP 5.4 library to control dynamic image assets in a cloud environment

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jordon Scott

aws image azure google cloud

20/01 2015

1.1.1

1.1.1.0

A PHP 5.4 library to control dynamic image assets in a cloud environment

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jordon Scott

aws image azure google cloud

20/01 2015

1.1.0

1.1.0.0

A PHP 5.4 library to control dynamic image assets in a cloud environment

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jordon Scott

aws image azure google cloud

07/01 2015

1.0.3

1.0.3.0

A PHP 5.4 library to control dynamic image assets in a cloud environment

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jordon Scott

aws image azure google cloud

14/10 2014

1.0.2

1.0.2.0

A PHP 5.4 library to control dynamic image assets in a cloud environment

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jordon Scott

aws image azure google cloud

26/05 2014

1.0.1

1.0.1.0

A PHP 5.4 library to control dynamic image assets in a cloud environment

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jordon Scott

aws image azure google cloud

24/04 2014

1.0.0

1.0.0.0

A PHP 5.4 library to control dynamic image assets in a cloud environment

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jordon Scott

aws image azure google cloud

23/04 2014

0.0.2-beta

0.0.2.0-beta

A PHP 5.4 library to control dynamic image assets in a cloud environment

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jordon Scott

aws image azure google cloud

22/04 2014

0.0.1-beta

0.0.1.0-beta

A PHP 5.4 library to control dynamic image assets in a cloud environment

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jordon Scott

aws image azure google cloud