gpt4 book ai didi

php - 获取错误 : Image source not readable in Laravel

转载 作者:行者123 更新时间:2023-12-04 16:12:13 38 4
gpt4 key购买 nike

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

Intervention \ Image \ Exception \ NotReadableException Image source not readable



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);

我还用 "intervention/image": "dev-master" 更新了我的 Composer 在 config/app.php
有人请帮忙吗?提前致谢。

最佳答案

试试这个代码

$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;

希望这会有所帮助!

关于php - 获取错误 : Image source not readable in Laravel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59279736/

38 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com