有人能帮我如何在Laravel中实现图像大小调整吗?我只有这个代码:
控制器
/* Save Image in Floder public>storage>images>service_request */
$nameFile = $service_request_id."_".date("Ymdhis")."_";
$count = 1;
for($i=1 ; $i<=3 ; $i++){
if($request->hasFile('problem_image'.$i)){
//$md5Name = md5_file($request->file('service_request')->getRealPath());
$md5Name = $nameFile.str_pad($count, 3, '0', STR_PAD_LEFT);
$guessExtension = $request->file('problem_image'.$i)->guessExtension();
$image = $request->file('problem_image'.$i);
$filename = $md5Name.'.'.$guessExtension;
$image_resize = Image::make($image->getRealPath());
$image_resize->resize(300, 300);
$file = $image_resize->storeAs('images/service_request', $filename, 'public' );
$ImageServiceRequest = new ImageServiceRequest;
$ImageServiceRequest->service_request_id = $service_request_id;
$ImageServiceRequest->image = $file;
$ImageServiceRequest->status = 'Active';
$ImageServiceRequest->create_by = Auth::user()->id;;
$ImageServiceRequest->save();
$count++;
}
您可能正在使用编号为problem_image
的。
更改这行代码。
发件人:
$image = $request->file('problem_image');
收件人:
$image = $request->file('problem_image'.$i);
希望这会有所帮助。