首页 > 解决方案 > Laravel 5.5 + 图像不可读错误(使用干预\图像)

问题描述

我使用 ImageOptimizer 包来减小图像大小。来源:http: //image.intervention.io/getting_started/installation

在控制器中:

if (Input::hasFile('title_image')) {

    $Product = Input::file('title_image');
    $filename = time() . '.' . $Product->getClientOriginalExtension();

    Image::make($Product)->resize(300, 300)->save( public_path('/uploads/avatars/' . $filename) )->move(public_path() . '/../../products', md5($Product->getClientOriginalName()) . ".png");

    $product->title_img = "products/" . md5($Product->getClientOriginalName()) . ".png";

    }

我该如何解决这个错误???:

图像不可读

标签: phplaravel-5resize

解决方案


getRealPath()上传图片时使用。

if (Input::hasFile('title_image')) {

    $Product = Input::file('title_image');
    $filename = time() . '.' . $Product->getClientOriginalExtension();

    Image::make($Product->getRealPath())->resize(300, 300)->save( public_path('/uploads/avatars/' . $filename) )->move(public_path() . '/../../products', md5($Product->getClientOriginalName()) . ".png");

    $product->title_img = "products/" . md5($Product->getClientOriginalName()) . ".png";
}

推荐阅读