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:
1 |
composer require intervention/image |
3. Open your config/app.php and add the following lines:
In the providers array add the service provider for the package
1 |
InterventionImageImageServiceProvider::class |
Add the Facade of the package to the aliases array
1 |
'Image' => InterventionImageFacadesImage::class |
4. Open up your routes.php and add this:
1 2 3 4 5 |
Route::get('/', function(){ $img = Image::make(public_path('uploads/adam-wathan.jpg'))->greyscale(); return $img->response('jpg'); }); |
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:
1 |
$ php artisan vendor:publish --provider="InterventionImageImageServiceProviderLaravel5" |
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.

- How to build your own Youtube – Part 10 - August 1, 2016
- How to build your own Youtube – Part 9 - July 25, 2016
- How to build your own Youtube – Part 8 - July 23, 2016
- How to build your own Youtube – Part 6 - July 6, 2016
- Introducing Laravel Password v1.0 - July 3, 2016
- How to build your own Youtube – Part 5 - June 28, 2016
- How to build your own Youtube – Part 4 - June 23, 2016
- How to build your own Youtube – Part 3 - June 15, 2016
- How to build your own Youtube – Part 2 - June 8, 2016
- How to build your own Youtube – Part 1 - June 1, 2016