I am implementing some image manipulation using great intervention library on Laravel 5. It works fine if image is small, like under 700KB with size lower than 800px wide.
But its not able to handle large size images, I want to upload images as big as 8 MB with 2000px wide.
I have tried classic way of bumping the memory_limit
but its not working
ini_set("memory_limit","20M");
Is there any solution which can work without killing the server.
Here is the code of my Upload service. It takes image from Request::file('file')
and Resize it to 3 sizes using intervention.
- Big size which is max width of 2000 px, then a
- Medium 800px wide
Thumb is 200px wide
public function photo($file) { $me = Auth::user(); //user folder for upload $userFolder = $me->media_folder; //Check the folder exist, if not create one if($this->setupUsrFolder($userFolder)) { //Unique filename for image $filename = $this->getUniqueFilename($userFolder); //Bump the memory to perform the image manipulation ini_set("memory_limit","20M"); //Generate thumb, medium, and max_width image $img = Image::make($file); //big_img $big = $img->resize(config('go.img.max_width'), null, function ($constraint) { $constraint->aspectRatio(); $constraint->upsize(); }); //Big Image $big->save($this->getPhotoPath($filename, $userFolder, 'b_')); //Medium image $med = $big->resize(config('go.img.med_width'), null, function ($constraint) { $constraint->aspectRatio(); $constraint->upsize(); }); $med->save($this->getPhotoPath($filename, $userFolder, 'm_')); //Thumbnail $thumb = $med->resize(config('go.img.thumb_width'), null, function ($constraint) { $constraint->aspectRatio(); $constraint->upsize(); }); $thumb->save($this->getPhotoPath($filename, $userFolder, 't_')); return $filename; } return null; }
Please help me how I can make it more efficient on and fast
$img
for$med
and$thumb
as you did with$big
. After each->save()
, use->destroy()
. Andini_set("memory_limit","20M");
is very low by the way. – Copulation->destroy()
and memory will be 48M, @Devon ya its setting the memory to 20MB but its not working, giving same error. – Avisavitaminosisimagesx() 19 is not a valid Image resource
after calling->destroy()
on saving every image – Avisavitaminosis->destory()
, it seem that it is destroying the image object so no other resizing is possible. Thank again for help. – Avisavitaminosisimagesx() 19 is not a valid Image resource
– Avisavitaminosis->destroy()
also gives meimagesx() 19
error. Try using$img
for all instances, get rid of$big =, $med = and $thumb =
. That should work, if not, doImage::make
and->destroy()
for each instance, this worked for me withoutimagesx() 19
error. – CopulationImage::make($file)->resize(2000, null)->save('big.jpg')->resize(800, null)->save('med.jpg')->resize(200, null)->save('thumb.jpg')->destroy()
; or call individually likeImage::make($file)->resize(2000, null)->save('big.jpg')->destroy() ... and others
– Avisavitaminosis