fixed for -- Unsupported image type image/vnd.microsoft.icon. GD driver is only able to decode JPG, PNG, GIF, BMP or WebP files.

This commit is contained in:
Edward Yang 2022-07-13 14:31:15 +08:00
parent 8e16e3a484
commit 3aa42e8055
1 changed files with 18 additions and 13 deletions

View File

@ -12,6 +12,7 @@
namespace Beike\Services;
use Intervention\Image\Facades\Image;
use Intervention\Image\Exception\NotReadableException;
class ImageService
{
@ -43,6 +44,7 @@ class ImageService
*/
public function resize(int $width = 100, int $height = 100): string
{
try {
$extension = pathinfo($this->imagePath, PATHINFO_EXTENSION);
$newImage = 'cache/' . mb_substr($this->image, 0, mb_strrpos($this->image, '.')) . '-' . $width . 'x' . $height . '.' . $extension;
@ -60,6 +62,9 @@ class ImageService
$canvas->save($newImagePath);
}
return asset($newImage);
} catch (NotReadableException $e) {
return $this->originUrl();
}
}