I am using laravel 5 and intervention, and would like to store multiple sizes of a image when it is uploaded via a form. Can anybody guide me
1 Answers
So i don't know what you already did. So let's start from the beginning.
First of all you need the Intervention Library. So switch to your main Folder (containing your composer.json file) And type
composer.phar require intervention/image
Or just add "intervention/image": "~2.1" to your require array in composer.json. ( And do a composer update after that )
"require": {
"laravel/framework": "5.0.*",
"intervention/image": "~2.1"
},
Now you have to add
'Intervention\Image\ImageServiceProvider',
to the providers array
and
'Image' => 'Intervention\Image\Facades\Image'
to your aliases Array. Both in config/app.php
Now you could create a "upload function" somewhere in a controller like
public function upload() {
$image = \Image::make(\Input::file('image'));
$path = storage_path('app')."/";
// encode image to png
$image->encode('png');
// save original
$image->save($path."original.png");
//resize
$image->resize(300,200);
// save resized
$image->save($path."resized.png");
}
This would save two images to the storage/app folder. One in the original size and one resized to 300x200.
This code is only an example, it does not contain any checks, for valid images or stuff like that. It just takes a file (assuming an image) and saves it two times. And of course you also don't need to encode to png...

- 6,700
- 4
- 28
- 52
-
I have this error: NotSupportedException in Driver.php line 18: ImageMagick module not available with this PHP installation. – Leoh Aug 17 '15 at 14:22
-
http://image.intervention.io/getting_started/configuration try to change to gd driver – shock_gone_wild Aug 17 '15 at 16:02
-
I already tried.. give me this error with the GD driver: NotReadableException in AbstractDecoder.php line 294: Image source not readable – Leoh Aug 17 '15 at 18:41
-
What if I want to save in another size like 100X100 can I use the same instance `$image`? – llioor Dec 28 '17 at 16:22
-
doesn't work for me this way. I need a new $image instance (like $image2) for the second size.. – subdesign Sep 21 '21 at 12:43
-
@subdesign whats your error? – shock_gone_wild Sep 21 '21 at 16:31