我正在使用 Laravel 5 和强大的 intervention 库 实现一些图像处理。如果图片很小,比如大小低于800像素宽且小于700KB,则可以正常工作。
但是,当处理大尺寸图片时,例如8 MB大小和2000像素宽度,则无法处理。我已经尝试了传统的增加
但是,当处理大尺寸图片时,例如8 MB大小和2000像素宽度,则无法处理。我已经尝试了传统的增加
memory_limit
的方法,但并没有起作用。ini_set("memory_limit","20M");
有没有一种解决方案可以在不关闭服务器的情况下工作。
这是我的上传服务代码。它从Request::file('file')
中获取图像,并使用 intervention 调整大小为 3 种尺寸。
- 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; }
请帮助我如何使其更高效和快速
$med
作为$img
,并像处理$big
一样处理$thumb
。在每个->save()
之后,使用->destroy()
。顺便说一下,ini_set("memory_limit","20M")
非常低。 - user2094178->destroy()
,内存将会是48M。@Devon,是的,它将内存设置为20MB,但是它不起作用,仍然报同样的错误。 - Saqueib->destroy()
时出现imagesx() 19不是有效的图像资源
。 - Saqueib