gpt4 book ai didi

php - AbstractDecoder.php 第 302 行中的 NotReadableException : Image source not readable

转载 作者:行者123 更新时间:2023-11-29 02:53:50 33 4
gpt4 key购买 nike

我试图按照有关插入图像并调整其大小的教程进行操作,但我遇到了一个显示图像源不可读的问题。

我正在使用 PHP、Laravel 5 框架和 mysql。当我运行我的代码时,我停止在 Image::make

这是我的 Controller 代码:

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Requests\FoodRequest;
use App\Http\Controllers\Controller;
use App\Photo;
use Image;
use App\Restaurant;
use Symfony\Component\HttpFoundation\File\UploadedFile;

public function addPhoto($zip, $street, Request $request)
{
$this->validate($request, [
'photo' => 'required|mimes:jpg,jpeg,png,bmp'
]);
$photo = $this->makePhoto($request->file('photo'));
Restaurant::locatedAt($zip, $street)->addPhoto($photo);
}

protected function makePhoto(UploadedFile $file)
{
return Photo::named($file->getClientOriginalName())
->move($file);
}

这是图片代码:

public static function named($name)
{
return (new static)->saveAs($name);
}

protected function saveAs($name)
{
$this->name = sprintf("%s-%s", time(), $name);
$this->path = sprintf("%s-%s", $this->baseDir, $this->name);
$this->thumbnail_path = sprintf("%s/tn-%s", $this->baseDir, $this->name);
return $this;
}

public function move(UploadedFile $file)
{
$file->move($this->baseDir, $this->name);
$this->makeThumbnail();
return $this;
}

protected function makeThumbnail()
{
Image::make($this->path)
->fit(200)
->save($this->thumbnail_path);
}

最佳答案

我做了同样的教程,你应该这样做:

Image::make($this->path.$this->name)->resize(128, 
128)->save($this->thumbnail_path.$this->name);

而不是这样做:

Image::make($this->path)->fit(200)->save($this->thumbnail_path);

关于php - AbstractDecoder.php 第 302 行中的 NotReadableException : Image source not readable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32784863/

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