dev-master
9999999-devImagine filter to resize and pad images to a set width and height
MIT
The Requires
- php >=5.3.0
- imagine/imagine ~0.5.0
by Ryan Tablada
Wallogit.com
2017 © Pedro Peláez
Imagine filter to resize and pad images to a set width and height
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)
Add "rtablada/resize-and-pad": "dev-master" to your composer.json file., (*2)
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);
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);
}
]
]);
Imagine filter to resize and pad images to a set width and height
MIT