ErrorException:imagecreatetruecolor():Intervention \ Image \ Image :: resize()时文件中的图像尺寸无效>> [

问题描述 投票:1回答:1
我正在Laravel项目上,我需要调整图像大小并从控制器作为文件返回。如果图像的width或height参数等于0,则必须计算另一个参数。我这样尝试过(因为我在库http://image.intervention.io/api/resize的文档中找到了它):

public function viewImage($w, $h, $path){ $image = Image::where('path', $path)->first(); if($image){ $manager = new ImageManager(array('driver' => 'gd')); if ($w === 0){ $img = $manager->make(asset("storage/galleries/".$image->fullpath)) ->resize($w, $h, function ($constraint) { $constraint->aspectRatio(); }); return $img->response('jpg'); } else{ if ($h === 0){ $img = $manager->make(asset("storage/galleries/".$image->fullpath)) ->resize($w, $h, function ($constraint) { $constraint->aspectRatio(); }); return $img->response('jpg'); } $img = $manager->make(asset("storage/galleries/".$image->fullpath))->resize($w, $h); return $img->response('jpg'); } } ...

但是它给我这样的错误:

ErrorException: imagecreatetruecolor(): Invalid image dimensions in file C:\xampp\htdocs\PROGRAMATOR.SK_API\vendor\intervention\image\src\Intervention\Image\Gd\Commands\ResizeCommand.php on line 47

我使用Intervention \ Image \ Image库

您能帮我吗?

我正在Laravel项目上,我需要调整图像大小并从控制器作为文件返回。如果图像的width或height参数等于0,则必须计算另一个参数。我这样尝试过...

php laravel image api image-resizing
1个回答
0
投票
首先,laravel返回字符串中的路由参数。因此$w$h是字符串。您有这些选项
© www.soinside.com 2019 - 2024. All rights reserved.