我已成功上傳圖片。但是在上傳圖像之前嘗試調整大小時出現以下錯誤。
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;
希望這會有所幫助!