我试图保存已上传图像的调整大小的副本,但图像干预似乎不知道从哪个根目录开始,或者可能只有我不知道如何对其进行属性配置。
这是我在AvatarImageController@store
中的代码
public function store(Request $request, Game $game)
{
if ($request->hasFile('game_image')) {
$request->validate([
'game_image' => 'mimes:jpeg,png|max:1014'
]);
$file = $request->file('game_image');
$filename_thumbnail = "thumb_". $file->hashName();
$path_full = $request->file('game_image')->store('images/test_folder');
$path_thumb = $request->file('game_image')->storeAs('images/test_folder/thumbs', $filename_thumbnail);
// resize image
$path_thumb = Intervention::make("./storage/app/public/" . $path_thumb)->resize(300, 200);
$path_thumb->save();
$image = new Image;
$image->full = basename($path_full);
$image->thumb = $filename_thumbnail;
$game->images()->save($image);
return back()->with('success', "Success!! Image uploaded.");
}else{
return back()->with('success', 'Ooops.. something went wrong.');
}
abort(500, 'Could not upload image :(');
}
我收到的错误:
InterventionImageExceptionNotReadableException
Image source not readable
我怀疑这是因为我没有在正确的路径上,因为上面的这些行函数:
// resize image
$path_thumb = Intervention::make("./storage/app/public/" . $path_thumb)->resize(300, 200);
$path_thumb->save();
当使用git作为部署时,使用显式路径是一个真正的麻烦。
您可以直接这样制作图像:
$uploadedFile = $request->file('game_image');
$image = Image::make($uploadedFile);
调整大小:
$image = $image->resize(300, 200);
并这样保存:
$image_data = $image->encode('jpg')->__toString();
$relative_file_path = 'images/test_folder/';
Storage::put($relative_file_path, $image_data)
是否使用storage((助手?
Intervention::make(storage_path('app/public/") . $path_thumb)