加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

php – 调整图像文件laravel 5

发布时间:2020-12-14 19:39:22 所属栏目:大数据 来源:网络整理
导读:我安装了补
我安装了补丁“干预/图像”,“必须掌握”,以使我的图像将其大小减少到300乘以300.
我做了一些表格,在我看来总是犯同样的错误.

在字符串上调用成员函数resize()

得到错误?

调节器

public function updateProfile() {

    $file = Input::file('imagem');
    $profileData = Input::except('_token');
    $validation = Validator::make($profileData,User::$profileData);
    if ($validation->passes()) {
        if ($file == null) {
            User::where('id',Input::get('id'))->update($profileData);
            Session::flash('message','Perfil editado com sucesso');
            return view('backend/perfil.index'); 
        }
        $file = array_get($profileData,'imagem');
        $destinationPath = 'imagens/perfil';
        $extension = $file->getClientOriginalExtension();
        $filename = rand(22222,99999) . '.' . $extension;
        $reduzir = $filename -> resize (300,300); 
        $profileData['imagem'] = $filename;
        $upload_success = $file->move($destinationPath,$filename);


        User::where('id',Input::get('id'))->update($profileData);
        Session::flash('message','Perfil editado com sucesso');
        return Redirect::to('backend/perfil');
    } else {
        return Redirect::to('backend/perfil')->withInput()->withErrors($validation);
    }
}

解决方法

问题可能是由于这些原因

您是否在app.php中添加了此别名

'aliases' => [
         //add these three at the bottom
        'Form'      => IlluminateHtmlFormFacade::class,'HTML'      => IlluminateHtmlHtmlFacade::class,'Image'     => InterventionImageFacadesImage::class
],

我相信你已经有了form和html帮助器.

并在Controller中使用此功能

即,只需将图像和大小值作为参数传递给此函数

在控制器中,您只需调用以下函数即可

$resizedImage  =   $this->resize($image,$request->get('image_size'));

并且resize()函数如下所示

private function resize($image,$size)
    {
        try 
        {
            $extension      =   $image->getClientOriginalExtension();
            $imageRealPath  =   $image->getRealPath();
            $thumbName      =   'thumb_'. $image->getClientOriginalName();

            //$imageManager = new ImageManager(); // use this if you don't want facade style code
            //$img = $imageManager->make($imageRealPath);

            $img = Image::make($imageRealPath); // use this if you want facade style code
            $img->resize(intval($size),null,function($constraint) {
                 $constraint->aspectRatio();
            });
            return $img->save(public_path('images'). '/'. $thumbName);
        }
        catch(Exception $e)
        {
            return false;
        }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读