Step 1: Install Laravel Intervention Image
Install the intervention with the composer package manager.
composer require intervention/image
<?php 'providers' => [ Intervention\Image\ImageServiceProvider::class ]
<?php 'aliases' => [ 'Image' => Intervention\Image\Facades\Image::class ]
Step 2: Publish Intervention Image Configuration
If you need to publish the configuration do run the command below. This command will create "/config/image.php" and from within the config file you can change the image driver from either "gd" or "imagick".
php artisan vendor:publish --provider="Intervention\Image\ImageServiceProviderLaravelRecent"
Start using Intervention Image
With Laravel Intervention Image you can pretty much perform many actions such as the following. Do note that each of the function can be chained for example like maybe when you want to perform "image resize", "reduce image quality" and "apply filters.
- backup()
- blur()
- brightness()
- cache()
- canvas()
- circle()
- colorize()
- contrast()
- crop()
- destroy()
- ellipse()
- encode()
- exif()
- filesize()
- fill()
- filter()
- flip()
- fit()
- gamma()
- getCore()
- greyscale()
- height()
- heighten()
- insert()
- interlace()
- invert()
- iptc()
- limitColors()
- line()
- make()
- mask()
- mime()
- opacity()
- orientate()
- pickColor()
- pixel()
- pixelate()
- polygon()
- rectangle()
- reset()
- resize()
- resizeCanvas()
- response()
- rotate()
- save()
- sharpen()
- stream()
- text()
- trim()
- widen()
- width()
Laravel Inervention Image Code Example
Below is the code example of initialising an image into the Image facade and then resizing it to have a 300px width and 200px height and returning it to the front end as a jpg response.
<?php // routes/web.php Route::get('/', function() { $img = Image::make('foo.jpg')->resize(300, 200); return $img->response('jpg'); });
Leave a reply