LARAVEL

How to Grayscale Images in Laravel 5


I’ll show you how to grayscale images very easily in Laravel 5.

1.Create a fresh install of Laravel 5

2. Require the intervention/image PHP library by running this from your terminal:

3. Open your config/app.php and add the following lines:

In the providers array add the service provider for the package

Add the Facade of the package to the aliases array

4. Open up your routes.php and add this:

The public_path function returns the fully qualified path to the public directory.

In the public directory, I created the uploads folder and added a normal colored file named adam-wathan.jpg

This is how the file looks normally:

Run your Laravel app and check the browser to see the results.

This is mine:

 

Note: Intervention/image uses PHP’S GD library to process all images. If you don’t have it enabled on your system or server, it won’t work and if you want to use Imagick, go ahead and publish the config files like so by running this command from the terminal:

This artisan command will create a file named image.php in the config folder. You can alter the settings in that file to use Imagick as the image processing library.

The Version of Laravel 5 used for this tutorial is 5.1.10.

Check Out the GitHub repo for this tutorial.

Please let me know if you have any questions in the comments section below.  :smile:

PROSPER OTEMUYIWA

About PROSPER OTEMUYIWA

Food Ninja, Code Slinger, Technical Trainer, Accidental Writer, Open Source Advocate and Developer Evangelist.