1. Installation
1). To get started with image, add to your composer.json
file as a dependency:
composer require intervention/image
2). Integration in Laravel
After installing the image library, register the Intervention\Image\ImageServiceProvider
in your config/app.php
configuration file:
'providers' => [
// ...
Intervention\Image\ImageServiceProvider::class,
],
Also, add the Image facade to the aliases array in your app configuration file:
'aliases' => [
// ...
'Image' => Intervention\Image\Facades\Image::class,
],
2. Configuration
Currently Intervention Image supports two Image processing extensions.
- GD
- Imagick
Make sure you have one of these installed in your PHP environment, before you start.
You're able to configure Intervention Image to use one of these libraries for all its operations. Just pass the configuration as an array directly into the ImageManager.
Example
// include composer autoload
require 'vendor/autoload.php';
// import the Intervention Image Manager Class
use Intervention\Image\ImageManager;
// create an image manager instance with favored driver
$manager = new ImageManager(array('driver' => 'imagick'));
// to finally create image instances
$image = $manager->make('public/foo.jpg')->resize(300, 200);
You might also use the static version of ImageManager as shown in the example below.
Static Example
// include composer autoload
require 'vendor/autoload.php';
// import the Intervention Image Manager Class
use Intervention\Image\ImageManagerStatic as Image;
// configure with favored image driver (gd by default)
Image::configure(array('driver' => 'imagick'));
// and you are ready to go ...
$image = Image::make('public/foo.jpg')->resize(300, 200);
After installing the image library, register the Intervention\Image\ImageServiceProvider
in your config/app.php
configuration file:
'providers' => [
// ...
Intervention\Image\ImageServiceProvider::class,
],
Also, add the Image facade to the aliases array in your app configuration file:
'aliases' => [
// ...
'Image' => Intervention\Image\Facades\Image::class,
],
If you're using Laravel, you can pull a configuration file into your application by running the following artisan command.
php artisan vendor:publish --provider="Intervention\Image\ImageServiceProviderLaravel5"
In Laravel 5 applications the configuration file is copied to config/image.php
, With this copy you can alter the image driver settings for you application locally and define which library should be used by all commands:
return array(
'driver' => 'imagick'
);
Currently you can choose between gd
and imagick
support.
3. Basic Usage
// open an image file and resize it
$img = Image::make('images/avatar.jpg')->resize(200, 200);
// resize image instance
$img->resize(320, 240);
// insert a watermark at special position
$img->insert('images/watermark.png', 'bottom-right', 15, 10);
// save image in desired format
$img->save('images/new_avatar.jpg');
// also you can do that like this
$img = Image::make('images/avatar.jpg')->resize(200, 200)->insert('images/new_avatar.jpg', 'bottom-right', 15, 10);
That's it! �� �� ��
4. More usage
- Image Uploads;
- Image Cache;
- Image Filters;
- URL Manipulation;