Saq*_*eib 9 php laravel intervention
我正在Laravel 5 上使用出色的干预库实现一些图像处理。如果图像很小,比如小于 700KB,宽度小于 800px,它就可以正常工作。
但它无法处理大尺寸图像,我想上传 8 MB 宽、2000 像素宽的图像。
我尝试过经典的碰撞方式,memory_limit但它不起作用
ini_set("memory_limit","20M");
Run Code Online (Sandbox Code Playgroud)
有没有什么解决方案可以在不杀死服务器的情况下工作。
这是我的上传服务的代码。它Request::file('file')使用干预从图像中提取图像并将其调整为 3 个尺寸。
拇指宽 200px
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;
}
Run Code Online (Sandbox Code Playgroud)请帮助我如何提高效率和速度
FWIW,评论的解决方案对我不起作用。也就是说,我无法让以下内容为我工作:
Image::make($file)->resize(2000, null)->save('big.jpg')->destroy();
Image::make($file)->resize(800, null)->save('med.jpg')->destroy();
Image::make($file)->resize(200, null)->save('thumb.jpg')->destroy();
Run Code Online (Sandbox Code Playgroud)
它仍然抛出以下错误:
Run Code Online (Sandbox Code Playgroud)Image::make($file)->resize(2000, null)->save('big.jpg')->destroy(); Image::make($file)->resize(800, null)->save('med.jpg')->destroy(); Image::make($file)->resize(200, null)->save('thumb.jpg')->destroy();
public function resize() {
ini_set('memory_limit', '256M');
// Do your Intervention/image operations...
}
// or...
ini_set('memory_limit', '256M');
Image::make($file)->resize(2000, null)->save('big.jpg');
Image::make($file)->resize(800, null)->save('med.jpg');
Image::make($file)->resize(200, null)->save('thumb.jpg');
Run Code Online (Sandbox Code Playgroud)
这成功地解决了问题。
原因是:
调整图像大小是一项非常消耗内存的任务。您不能假设 1MB 的图像占用 1MB 的内存。例如,将 3000 x 2000 像素图像调整为 300 x 200 可能需要多达 32MB 的内存。即使图像小于 1MB 文件大小。
@奥利弗沃格尔。2018. 已用完 134217728 字节的允许内存大小。[在线] 可在:https : //github.com/Intervention/image/issues/567#issuecomment-224230343 获得。[2018 年 6 月 14 日访问]。
| 归档时间: |
|
| 查看次数: |
5595 次 |
| 最近记录: |