使用Laravel图像干预调整图像大小';别让我存钱
我最难用Laravel图像干预调整图像大小。我可以正常命名和保存图像,但当我添加图像干预时,它不会将创建的新文件保存到文件夹中 这是我的控制器里的东西使用Laravel图像干预调整图像大小';别让我存钱,laravel,image,resize,intervention,Laravel,Image,Resize,Intervention,我最难用Laravel图像干预调整图像大小。我可以正常命名和保存图像,但当我添加图像干预时,它不会将创建的新文件保存到文件夹中 这是我的控制器里的东西 //This all works $title = str_slug(request('title')); $filenameWithExt = $request->file('cover_image')->getClientOriginalName(); $filename = pa
//This all works
$title = str_slug(request('title'));
$filenameWithExt = $request->file('cover_image')->getClientOriginalName();
$filename = pathinfo($filenameWithExt, PATHINFO_FILENAME);
$extension = $request->file('cover_image')->getClientOriginalExtension();
$fileNameToStore= $title.'.'.$extension;
$thumbnailpic= 'thumb'.'-'.$fileNameToStore;
//store image
$path = $request->file('cover_image')->storeAs('public/cover_images', $fileNameToStore);
//Here is where I am trying to resize and it breaks
$file = Input::file('cover_image');
Image::make( $file->getRealPath() )->fit(340, 340)->save('public/cover_images/' . $thumbnailpic);
这就是我得到的错误
"Can't write image data to path (public/cover_images/thumb-imagename.png)"
如果我删除了两行调整大小的代码,一切都会很好地工作。我正在本地运行此程序,并已将所有内容完全打开以获取权限。不知道还能做什么。谢谢 问题似乎与保存路径有关,您能否尝试这样给出完整路径
$targetPath = storage_path().'/app/public/cover_images/';
...
->save($targetPath . $thumbnailpic);
我希望这会有所帮助,所以我终于找到了答案。我当时正在为公众保存图像干预显然不喜欢的路径。所以我使用了下面的代码
$source = storage_path().'/app/public/cover_images/'.$fileNameToStore;
$target = storage_path().'/app/public/cover_images/' . $thumbnailpic;
Image::make($source)->fit(140, 140)->save($target);
成功了 目录
cover\u images
是否存在?是否存在。Laravel本身创建文件夹并保存在那里没有问题,似乎图像干预存在问题->save('public/cover_images/'.$thumbnailpic)
,对于干预,我相信此路径从Linux根目录开始。这意味着什么?遗憾的是,即使这样,我仍然会遇到错误“无法将图像数据写入路径”(public/cover_images/thumb imagename.png)“你确定你的$file->getRealPath()
正在返回图像吗?因为make
需要获取真实图像路径作为参数。我如何判断$file->getRealPath()是否正在返回图像?你可以使用dd
进行此操作,dd($file->getRealPath())
所以,您可以在浏览器上检查命令输出。当我使用它时,我会得到“/private/var/tmp/phphqoRVm”我猜这不对吗?