【问题标题】:Laravel intervention/image doesn't resize imageLaravel 干预/图像不会调整图像大小
【发布时间】:2017-03-28 04:45:35
【问题描述】:

我正在尝试使用 laravel 干预插件。我安装它没有问题,但不能使用它。 我正在尝试制作一个返回调整大小图像的测试函数,但没有成功; 我认为问题可能出在图像路径中,请帮我修复我的代码。

function test($img)
{
   /* $img = Image::make('public/image1.jpg');
    $img->resize(300, 200);
    return $img; */

   $image = Image::make('http://localhost/cms/digital-cms/public/image1.jpg')->resize(200, 200, function ($c) {
        $c->aspectRatio();
        $c->upsize();
    });
    return $image;

    //$h=200; $w=200;
    //return Image::make(public_path('public/image1.jpg')->resize($h, $w)->response('jpg'));
}

【问题讨论】:

    标签: laravel resize intervention


    【解决方案1】:

    就我而言,我正在调整大小、裁剪(适合),但最终图像仍与原始图像相同。发现我必须添加函数编码,才能生成经过处理的图像

    return $image->encode('jpg', 80);
    

    【讨论】:

      【解决方案2】:
       //get image
       $image=$request->file('image');
       //rename image
       $input = time().'.'.$image->getClientOriginalExtension();
                  //your directory to upload
                  $destinationPath = 'main/images/company';
                  //save and resize image
                  $img = Image::make($image->getRealPath());
                  $img->resize(20,20, function ($constraint) {
                    $constraint->aspectRatio();
                    })->save($destinationPath.'/'.$input);
      

      【讨论】:

        【解决方案3】:

        您应该在Image 类上使用响应函数来返回图像

        $image = Image::make('http://localhost/cms/digital-cms/public/image1.jpg')->resize(200, 200, function ($c) {
            $c->aspectRatio();
            $c->upsize();
        });
        return $image->response();
        

        【讨论】:

        • 非常感谢您的时间和帮助。我改变了它,但结果是一样的。如果我写 dd($image->response());它显示了一些东西..在这里看图片。 imgur.com/a/LJA8s
        • 这是 laravel 响应对象。给我发了一张实际回复的图片
        • 它返回空。
        • 可能问题出在图片的网址上。尝试在本地而不是从 url 获取图像。 base_url().'/public/image1.jpg'
        猜你喜欢
        • 2018-09-21
        • 2018-11-21
        • 1970-01-01
        • 1970-01-01
        • 2023-01-24
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-03-23
        相关资源
        最近更新 更多