我想调整上传的图像大小,并存储在folder.then显示在网上。我在enctype="multipart/form-data"中使用了blade.php格式。文件在不调整大小的情况下成功地在web上显示。当试图调整图像大小时,我得到了错误
controller.php
public function dili(Request $request)
{
$di = new diligent;
$di->jobtype = $request->jobtype;
$di->jobC = $request->jobC;
$di->details = $request->details;
$image = $request->file('image');
$path = $image->getClientOriginalName();
$destinationPath = public_path('img');
Image::make($image)->resize(300, 100)->save($image);
$a = $image->move($destinationPath, $path);
$di->image = $path;
$di->save();
$de = diligent::all();
return view('admin')->with('dw', $de);
}错误消息
不支持编码格式(tmp)。
发布于 2019-09-17 06:19:35
1)在getRealPath()中使用图像::make()
2)在特定路径下保存图像。像这样试试。
if($request->hasFile('image')) {
$image = $request->file('image');
$filename = $image->getClientOriginalName();
$image_resize = Image::make($image->getRealPath());
$image_resize->resize(300, 100);
$image_resize->save(public_path('img/' .$filename));
}确保安装了图像干预库。
干预映像保存()方法需要一个文件名,以便它知道文件格式(jpg、png等)。来保存你的形象。
您获得错误的原因是不知道保存临时图像对象(tmp)的编码方式。
下面是一个例子
->save('my-image.jpg', 90)还有一个可选的第二个参数来控制质量输出。以上产品质量达90%。
http://image.intervention.io/api/save
https://stackoverflow.com/questions/57968323
复制相似问题