ImageHandler
The Image Handler is used to interact with image files on a specific source. When you call image()->source('local')
, it returns an ImageHandler.
You can access it from the Image facade:
$handler = Image::source(); // default source
$handler = image()->source('cloud'); // cloud source
Or build it manually
use Folklore\Image\Contracts\ImageHandler;
$handler = app(ImageHandler::class);
// And setting a source manually
$handler->setSource($source);
Methods
make($path, $options)
open($path)
save($image, $path)
format($path)
thumbnail($image, $width, $height, $crop)
getSource()
setSource($source)
getMemoryLimit()
setMemoryLimit($limit)
getImagineManager()
getImagine()
make($path, $options = array())
Make an image and apply options
Arguments
$path
(string)
The path of the image$options
(array)
The manipulations to apply on the image
Return
(\Imagine\Image\ImageInterface)
Examples
Create an Image object with the image resized (and cropped) to 300x300 and rotated 180 degrees.
$handler = Image::source();
$image = $handler->make('path/to/image.jpg', [
'width' => 300,
'height' => 300,
'crop' => true,
'rotate' => 180
]);
open($path)
Open an image from the source
Arguments
$path
(string)
The path of the image
Return
(\Imagine\Image\ImageInterface)
Examples
Open the image path and return an Image object
$handler = Image::source();
$image = $handler->open('path/to/image.jpg');
save($image, $path)
Save an image to the source
Arguments
$image
(\Imagine\Image\ImageInterface)
The image to save$path
(string)
The path where you want to save the image
Return
(string)
Examples
Create a resized image and save it to a new path
$handler = Image::source();
$image = $handler->make('path/to/image.jpg', [
'width' => 300,
'height' => 300,
'crop' => true
]);
$handler->save($image, 'path/to/image-resized.jpg');
Or save it to a different source:
$handler = Image::source();
$image = $handler->make('path/to/image.jpg', [
'width' => 300,
'height' => 300,
'crop' => true
]);
Image::source('cloud')->save($image, 'path/to/image-resized.jpg');
format($path)
Return an URL to process the image
Arguments
$path
(string)
The path of the image
Return
(string)
The format fo the image
Examples
Open the image path and return an Image object
$handler = Image::source();
$format = $handler->format('path/to/image.jpg');
// $format = 'jpg';
---
<a name="thumbnail" id="thumbnail"></a>
### `thumbnail($image, $width = null, $height = null, $crop = true)`
Create a thumbnail from an image
#### Arguments
- `$image` `(\Imagine\Image\ImageInterface|string)` An image instance or the path to an image
- `$width` `(integer)` The maximum width of the thumbnail
- `$height` `(integer)` The maximum height of the thumbnail
- `$crop` `(boolean|string)` If this is set to true, it match the exact size provided. You can also set a position for the cropped image (ex: 'top left')
#### Return
`(\Imagine\Image\ImageInterface)`
---
<a name="getSource" id="getSource"></a>
### `getSource()`
Get the image source
#### Return
`(\Folklore\Image\Contracts\Source)` The source that is used
---
<a name="setSource" id="setSource"></a>
### `setSource($source)`
Set the image source
Open the image path and return an Image object
```php
use Folklore\Image\Contracts\ImageHandler;
$handler = app(ImageHandler::class);
$source = Image::getSourceManager()->driver('local');
$handler->setSource($source);
Arguments
$source
(\Folklore\Image\Contracts\Source)
The source of the factory
Return
(\Folklore\Image\ImageHandler)
getMemoryLimit()
Get the memory limit
Return
(string)
setMemoryLimit($limit)
Set the memory limit
Arguments
$limit
(string)
The memory limit
Return
(\Folklore\Image\ImageHandler)
getImagineManager()
Get the imagine manager
Return
(\Folklore\Image\ImagineManager)
getImagine()
Get the imagine driver
Return
(\Imagine\Image\ImagineInterface)