【问题标题】:Gettign Error : Image source not readable in Laravel出现错误:图像源在 Laravel 中不可读
【发布时间】:2019-12-11 06:05:00
【问题描述】:

我已成功上传图片。但是在上传图片之前尝试调整大小时出现错误。

干预\图像\异常\NotReadableException 图片来源不可读

Controller.php

        $image=$request->product_image; 
        $thumbnailSize = '150X150';

        $upload_path='image/product/'.$request->product_name.'/';           

        $imageName = $request->product_name.time().'.'.$image->getClientOriginalExtension();

        $thumbnailImageName = $request->product_name.time().'.'.$image->getClientOriginalExtension().$thumbnailSize;

        $image_url = $upload_path.$imageName;

        $thumbnail_image_url = $upload_path.$thumbnailImageName;

        $image->move(storage_path($upload_path), $imageName);

        $resize_image = Image::make($image->getRealPath());

        $resize_image->resize(150, 150, function($constraint){
        $constraint->aspectRatio();
        })->save($upload_path);

我还在config/app.php 中用"intervention/image": "dev-master" 更新了我的作曲家

有人帮忙吗?提前致谢。

【问题讨论】:

    标签: php laravel image-resizing laravel-5.8


    【解决方案1】:

    试试这个代码

    $upload_path = storage_path().'image/product/'.$request->product_name.'/'; 
    
    $image=$request->product_image; 
    $imageName = $request->product_name.time().'.'.$image->getClientOriginalExtension();
    $image->move($upload_path, $imageName);
    
    $thumbnailSize = '150X150';
    $thumbnailImageName = $thumbnailSize.$imageName;
    File::copy($upload_path . $imageName, $upload_path . $thumbnailImageName);
    Image::make($upload_path . $thumbnailImageName)
    ->resize(150, 150, function($constraint){
    $constraint->aspectRatio();
    })->save($upload_path . $thumbnailImageName);
    

    在顶部添加这个

    use Image;
    use File;
    

    希望这会有所帮助!

    【讨论】:

    • 显示新错误Encoding format (jpg150X150) is not supported.
    • @ArafatRahman 在上面的代码中,$thumbnailImageName 名称具有错误的文件扩展名,当干预尝试对图像进行编码时,它发现“jpg150X150”作为扩展名。修复它,编码错误应该去或使用encode()方法手动编码
    猜你喜欢
    • 2018-05-05
    • 2016-12-19
    • 1970-01-01
    • 1970-01-01
    • 2016-07-09
    • 1970-01-01
    • 1970-01-01
    • 2015-02-19
    • 2019-04-22
    相关资源
    最近更新 更多