We can create thumbnail from Big size image in Laravel or in a Php script. For this, we will use a package for both Php and Laravel.
http://image.intervention.io/
https://github.com/Intervention/image
It gives an easier way to create, edit, and compose images and supports the two most common image processing libraries GD Library and Imagick.
Getting started
The library requires at least PHP version 5.4 and comes with Laravel Facades and Service Providers to simplify the optional framework integration.
Basic Examples
open an image file
$image = Image::make('public/woo.jpg');
now you are able to resize the instance
$image->resize(320, 240);
and insert a watermark for example
$image->insert('public/watermark.png');
lastly, we save the image as a new file
$image->save('public/newimage.jpg');
Method chaining
$image = Image::make('public/woo.jpg')->resize(320, 240)->insert('public/watermark.png');
Installation
System Requirements
Intervention Image requires the following components to work correctly.
PHP >= 5.4
Fileinfo Extension
And one of the following image libraries.
GD Library (>=2.0) … or …
Imagick PHP extension (>=6.5.7)
Composer Installation
The best way to install Intervention Image is quickly and easily with the Composer./
To install the latest version, run this command.
$ php composer.phar require intervention/image
Now your composer.json has been updated automatically and you’re able to require the just created
vendor/autoload.php file to PSR-4 autoloads the library.
Usage
Intervention Image doesn’t require Laravel or any other framework at all. If you want to use it as is, you just have to require the composer autoload file to instantiate image objects as shown in the following example.
Example
include composer autoload
require 'vendor/autoload.php';
import the Intervention Image Manager Class
use Intervention\Image\ImageManager;
create an image manager instance with the favored driver
$manager = new ImageManager(array('driver' => 'imagick'));
to finally create image instances
$image = $manager->make('public/foo.jpg')->resize(300, 200);
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);
Integration in Laravel
Intervention Image has optional support for Laravel and comes with a Service Provider and Facades for easy integration. The vendor/autoload.php is included by Laravel, so you don’t have to require or autoload manually.
After you have installed Intervention Image, open your Laravel config file config/app.php and add the following lines.
In the $providers array add the service providers for this package.
Intervention\Image\ImageServiceProvider::class
Add the facade of this package to the $aliases array.
'Image' => Intervention\Image\Facades\Image::class
Now the Image Class will be auto-loaded by Laravel.
Configuration
By default, Intervention Image uses PHP’s GD library extension to process all images. If you want to switch to Imagick, you can pull a configuration file into your application by running one of the following artisan commands.
Publish configuration in Laravel 5
$ php artisan vendor:publish --provider="Intervention\Image\ImageServiceProviderLaravel5"
Publish configuration in Laravel 4
$ php artisan config:publish intervention/image
Great content! Super high-quality! Keep it up! 🙂