nosupportedexception In AbstractEncoder.php line 200:不支持编码格式(tmp)
以前,我在Laravel Open-Admin中为我指定的存储路径上传图像。它工作正常。但是后来我不得不在上传的时候裁剪图片。然后我按照open admin https://open-admin.org/docs/en/model-form-upload的文档进行操作。它说安装干预/图像包并使用crop()裁剪图像。我这样写,
$form->image('cover_photo', __('Cover photo'))->crop(800,800,50,50);
,但它没有工作。一直显示这样的错误
NotSupportedException In AbstractEncoder.php line 200 :
Encoding format (tmp) is not supported.
这是我的控制器在open-admin
中的完整表单功能protected function form()
{
$form = new Form(new Book());
$form->text('name', __('Name'));
$form->ckeditor('description', __('Description'));
$form->image('cover_photo', __('Cover photo'))->crop(800,800,50,50);
return $form;
}
同样,我用几种方法修改了代码来解决这个错误,
$form->image('cover_photo', __('Cover photo'))->crop(800,800,50,50)->encode('jpg');
$form->image('cover_photo', __('Cover photo'))->crop(800,800,50,50)->encode('jpg',90);
$form->image('cover_photo', __('Cover photo'))->crop(800,800,50,50)->encode('jpg',75);
我检查了代码GD和imagick库,但错误是一样的。我检查了AbstractEncoder.php文件,错误显示about.
[2023-04-08 08:59:29] local.ERROR: Encoding format (tmp) is not supported. {"userId":1,"exception":"[object] (Intervention\Image\Exception\NotSupportedException(code: 0): Encoding format (tmp) is not supported. at F:\Office\Admin2\vendor\intervention\image\src\Intervention\Image\AbstractEncoder.php:200)
[stacktrace]
#0 F:\Office\Admin2\vendor\intervention\image\src\Intervention\Image\AbstractDriver.php(79): Intervention\Image\AbstractEncoder->process(Object(Intervention\Image\Image), 'tmp', NULL)
#1 F:\Office\Admin2\vendor\intervention\image\src\Intervention\Image\Image.php(121): Intervention\Image\AbstractDriver->encode(Object(Intervention\Image\Image), 'tmp', NULL)
#2 F:\Office\Admin2\vendor\intervention\image\src\Intervention\Image\Image.php(146): Intervention\Image\Image->encode('tmp', NULL)
#3 F:\Office\Admin2\vendor\open-admin-org\open-admin\src\Form\Field\Traits\ImageField.php(53): Intervention\Image\Image->save('C:\\wamp64\\tmp\\p...')
#4 F:\Office\Admin2\vendor\open-admin-org\open-admin\src\Form\Field\Image.php(53): OpenAdmin\Admin\Form\Field\Image->callInterventionMethods('C:\\wamp64\\tmp\\p...')
#5 F:\Office\Admin2\vendor\open-admin-org\open-admin\src\Form.php(913): OpenAdmin\Admin\Form\Field\Image->prepare(Object(Illuminate\Http\UploadedFile))
#6 F:\Office\Admin2\vendor\open-admin-org\open-admin\src\Form.php(358): OpenAdmin\Admin\Form->prepareInsert(Array)
我认为这些代码行影响了错误。
如果有人能给我一个解决这个问题的方法,那就太好了。谢谢你我想在Laravel open-admin中裁剪上传的图像
似乎.tmp
文件名后缀混淆了包。试着纠正这个错误:
protected function form()
{
$form = new Form(new Book());
$form->text('name', __('Name'));
$form->ckeditor('description', __('Description'));
$form->image('cover_photo', __('Cover photo'))
->crop(800, 800, 50, 50)
->move('public/cover_photos') // Set your desired folder
->uniqueName()
->saving(function (File $file) {
return $file->guessExtension();
});
return $form;
}