2017 © Pedro Peláez
 

library resize-and-pad

Imagine filter to resize and pad images to a set width and height

image

rtablada/resize-and-pad

Imagine filter to resize and pad images to a set width and height

  • Monday, February 24, 2014
  • by rtablada
  • Repository
  • 1 Watchers
  • 0 Stars
  • 239 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 1 % Grown

The README.md

Resize And Pad

This is a simple Imagine Filter to allow you to resize and pad images with whitespace to ensure consistent sizing without cropping or stretching., (*1)

Installing

Add "rtablada/resize-and-pad": "dev-master" to your composer.json file., (*2)

Use

Using this filter is quite similar to the Transformation Filter in Imagine. Inject your instance of Imagine and then call setSize. Here we will use a GD instance, but any instance of Imagine\Image\ImageInterface will do., (*3)

$imagine = new \Imagine\GD\Imagine;
$resizer = new \Rtablada\Images\ResizeAndPad($imagine);
$image = $imagine->open($pathToImage);

$resizer->setSize(200, 200);
$output = $resizer->apply($image);
$output->save($outputPath);

The setSize and apply functions allow for chaining so the above could be written like this:, (*4)

$resizer->setSize(200, 200)->apply($image)->save($outputPath);

Use with Stapler

This Filter was originally built for use within a Laravel project using Stapler. Using this filter with Stapler is quite simple when defining your styles:, (*5)

$this->hasAttachedFile('avatar', [
    'styles' => [
        'medium' => '300x300',
        'thumb' => function($file, $imagine) {
            $resizer = \Rtablada\Images\ResizeAndPad($imagine);
            return $resizer->setSize(100,100)->apply($file);
        }
    ]
]);

The Versions

24/02 2014

dev-master

9999999-dev

Imagine filter to resize and pad images to a set width and height

  Sources   Download

MIT

The Requires