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