Home / Snippets / Getting Started With Laravel Intervention Image
Getting Started With Laravel Intervention Image cover

Getting Started With Laravel Intervention Image

815

3 years ago

0 comments

In this snippet, you will learn how to get started with Laravel Intervention Image the easy way. Let's get started right away and get this thing going.

Step 1: Install Laravel Intervention Image


Install the intervention with the composer package manager.
composer require intervention/image
Include the provider and aliases in your "config/app.php" file like below.
<?php

'providers' => [ Intervention\Image\ImageServiceProvider::class ]
For the Laravel Intervention alias, it will be as follows.
<?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.

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');
});

Other Reads

notion avatar

Alaz

Week-end developer currently experimenting with web, mobile, and all things programming.

Topics:

Frontend

Resource

Average

Average

Support Us

If you like our tutorial, support us by being our Patreon or buy us some coffee ☕️

Welcome to PostSrc V3

PostSrc Dark Logo

You have to login to favorite this