rtablada / exif
A package for dealing with exif image orientation
Requires
- php: >=5.3.0
- imagine/imagine: ~0.5.0
This package is not auto-updated.
Last update: 2024-11-19 02:35:01 UTC
README
This is a simple class that allows you to auto-rotate your images based on EXIF data imbedded in JPG and TIFF images.
Installing
Add "rtablada/exif": "dev-master"
to your composer.json
file.
Use
Using this rotator takes a file path, SPLFileInfo instance, or Symfony\Request\UploadedFile along with an instance of Imagine (here we use GD).
Then call rotate
and you will be returned an auto-rotated image based on the EXIF data if any is present.
$imagine = new \Imagine\GD\Imagine; $rotator = new \Rtablada\Exif\ExifRotator($pathToFile, $imagine); $output = $resizer->rotate(); $output->save($outputPath);
Use with Stapler
This was originally built for use within a Laravel project using Stapler. Using this rotator with Stapler is quite simple when defining your styles:
$this->hasAttachedFile('avatar', [ 'styles' => [ 'medium' => '300x300', 'thumb' => function($file, $imagine) { $resizer = \Rtablada\Images\ResizeAndPad($file, $imagine); return $resizer->rotate(); } ] ]);
Shorthand
If you would like to quickly rotate an image you can use makeAndRotate
which skips the step of having to instantiate the rotator:
\Rtablada\Images\ResizeAndPad::makeAndRotate($file, $imagine)->save($output);