Php 上传到laravel 5.2后调整图像大小的问题
晚上好,当图像上传到我的网站上时,我想添加图像的调整大小功能,我已经安装了必要的依赖项,并且在config/app文件中包含了提供者和别名。但我发现这个错误:Php 上传到laravel 5.2后调整图像大小的问题,php,laravel,laravel-5,Php,Laravel,Laravel 5,晚上好,当图像上传到我的网站上时,我想添加图像的调整大小功能,我已经安装了必要的依赖项,并且在config/app文件中包含了提供者和别名。但我发现这个错误: production.ERROR:Method\Http\UploadedFile::resize不存在。 我把代码的一部分放在下面: public function imageProfile(Request $request) { $user = Auth::user(); $rule
production.ERROR:Method\Http\UploadedFile::resize不存在。
我把代码的一部分放在下面:
public function imageProfile(Request $request)
{
$user = Auth::user();
$rules = array(
'profile-image' => 'required|image|mimes:jpeg,png,jpg,gif|max:8192|dimensions:min_width=160,min_height=160',
);
$customMessages = [
'profile-image.required' => 'E\' richiesta una immagine per cambiare immagine di profilo.',
'profile-image.image' => 'Devi inserire un immagine valida.',
'profile-image.mimes' => 'L\'immagine inserita non ha un formato adatto.',
'profile-image.dimensions' => 'L\'immagine deve essere minimo 160x160.',
];
$validator = Validator::make(Input::all(), $rules, $customMessages);
if ($validator->fails()) {
return response()->json(['success' => false, 'error' => $this->validationErrorsToString($validator->errors())]);
}
if ($request->hasFile('profile-image')) {
$number = mt_rand(1,1000000);
$image = $request->file('profile-image');
$name = $user->username.'-'.Carbon::now()->toDateString().'-'.$number.'.'.$image->getClientOriginalExtension();
$destinationPath = 'uploads/profile';
$imagePath = $destinationPath. "/". $name;
$image->move($destinationPath, $name);
$image->resize(200,200);
$user->image_profile = $imagePath;
$user->save();
$html = $imagePath;
return response()->json(['success' => true, 'html' => $html, 'image' => $imagePath]);
}
}
谢谢您的帮助,祝您愉快Laravel没有默认的图像大小调整功能。但大多数laravel开发人员在处理图像时使用“图像干预”。(易于使用) 要安装(图像干预),请执行以下操作: 步骤1运行
composer require intervention/image
在config/app.php上执行第2步:
在$providers数组中,添加以下内容:
Intervention\Image\ImageServiceProvider::class
'Image' => Intervention\Image\Facades\Image::class
在$Alias数组中,添加以下内容:
Intervention\Image\ImageServiceProvider::class
'Image' => Intervention\Image\Facades\Image::class
如果您有问题,您的GD库丢失了,请将其全部安装
PHP5: sudo apt-get install php5-gd
PHP7: sudo apt-get install php7.0-gd
~~在控制器上使用~~
第3步在控制器顶部
use Intervention\Image\ImageManagerStatic as Image;
第四步介绍你的方法(有几种方法,但这会给你一个想法)
您正在使用干预图像包吗?文件上载对象中没有可用的调整大小功能。是的,完全是@kmg kumar。所以他需要使用图像干预,这个链接可以帮助你吗