修复 psd、tif 格式图片无法上传的bug
This commit is contained in:
@@ -22,6 +22,7 @@ use Illuminate\Support\Facades\Artisan;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\View\View;
|
||||
use Intervention\Image\Facades\Image as InterventionImage;
|
||||
use League\Flysystem\FilesystemException;
|
||||
use Symfony\Component\Console\Output\BufferedOutput;
|
||||
use Symfony\Component\HttpFoundation\StreamedResponse;
|
||||
@@ -156,7 +157,7 @@ class Controller extends BaseController
|
||||
// 是否启用了水印功能,跳过gif图片
|
||||
if ($image->group->configs->get(GroupConfigKey::IsEnableWatermark) && $image->mimetype !== 'image/gif') {
|
||||
$configs = $image->group->configs->get(GroupConfigKey::WatermarkConfigs);
|
||||
$contents = (string)$service->stickWatermark($contents, collect($configs))->encode();
|
||||
$contents = $service->stickWatermark($contents, collect($configs))->encode()->getEncoded();
|
||||
}
|
||||
$cacheTtl = (int)$image->group->configs->get(GroupConfigKey::ImageCacheTtl, 0);
|
||||
// 是否启用了缓存
|
||||
@@ -167,12 +168,21 @@ class Controller extends BaseController
|
||||
}
|
||||
}
|
||||
} catch (FilesystemException $e) {
|
||||
Utils::e($e, '图片输出时出现异常');
|
||||
abort(404);
|
||||
}
|
||||
|
||||
$mimetype = $image->mimetype;
|
||||
|
||||
// 浏览器无法预览的图片,改为 png 格式输出
|
||||
if (in_array($image->extension, ['psd', 'tif', 'bmp'])) {
|
||||
$mimetype = 'image/png';
|
||||
$contents = InterventionImage::make($contents)->encode('png')->getEncoded();
|
||||
}
|
||||
|
||||
return \response()->stream(function () use ($contents) {
|
||||
echo $contents;
|
||||
}, headers: ['Content-type' => $image->mimetype]);
|
||||
}, headers: ['Content-type' => $mimetype]);
|
||||
}
|
||||
|
||||
public function thumbnail(Request $request): StreamedResponse
|
||||
@@ -190,7 +200,7 @@ class Controller extends BaseController
|
||||
$contents = Cache::get($cacheKey);
|
||||
} else {
|
||||
$stream = $image->filesystem()->readStream($image->pathname);
|
||||
$img = \Intervention\Image\Facades\Image::make($stream);
|
||||
$img = InterventionImage::make($stream);
|
||||
|
||||
$width = $w = $image->width;
|
||||
$height = $h = $image->height;
|
||||
@@ -203,15 +213,16 @@ class Controller extends BaseController
|
||||
$height = (int)($h * $scale);
|
||||
}
|
||||
|
||||
$contents = $img->fit($width, $height, fn($constraint) => $constraint->upsize())->encode();
|
||||
$contents = $img->fit($width, $height, fn($constraint) => $constraint->upsize())->encode('png');
|
||||
Cache::rememberForever($cacheKey, fn () => (string)$contents);
|
||||
}
|
||||
} catch (FilesystemException $e) {
|
||||
Utils::e($e, '图片缩略图输出时出现异常');
|
||||
abort(404);
|
||||
}
|
||||
|
||||
return \response()->stream(function () use ($contents) {
|
||||
echo $contents;
|
||||
}, headers: ['Content-type' => $image->mimetype]);
|
||||
}, headers: ['Content-type' => 'image/png']);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
"fruitcake/laravel-cors": "^2.0.5",
|
||||
"guzzlehttp/guzzle": "^7.2",
|
||||
"intervention/image": "^2.7",
|
||||
"intervention/imagecache": "^2.5",
|
||||
"laravel/breeze": "^1.8",
|
||||
"laravel/framework": "^9.0",
|
||||
"laravel/sanctum": "^2.14",
|
||||
|
||||
Generated
+133
-1
@@ -4,7 +4,7 @@
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "87004ae9acac8c83e5f70ed79d85415c",
|
||||
"content-hash": "f55a4d1756ba393dba532f9d31cd9649",
|
||||
"packages": [
|
||||
{
|
||||
"name": "adbario/php-dot-notation",
|
||||
@@ -2065,6 +2065,73 @@
|
||||
],
|
||||
"time": "2021-12-16T16:49:26+00:00"
|
||||
},
|
||||
{
|
||||
"name": "intervention/imagecache",
|
||||
"version": "2.5.2",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/Intervention/imagecache.git",
|
||||
"reference": "270d1e72ddff2fc0a6d3c7e6cbc9d23c9ec1e3e4"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/Intervention/imagecache/zipball/270d1e72ddff2fc0a6d3c7e6cbc9d23c9ec1e3e4",
|
||||
"reference": "270d1e72ddff2fc0a6d3c7e6cbc9d23c9ec1e3e4",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"illuminate/cache": "^5.5|~6|~7|~8|~9",
|
||||
"illuminate/filesystem": "^5.5|~6|~7|~8|~9",
|
||||
"intervention/image": "~2.2",
|
||||
"nesbot/carbon": "^2.39",
|
||||
"opis/closure": "^3.5",
|
||||
"php": "~7.2|~8"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^8.0"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Intervention\\Image\\": "src/Intervention/Image"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Oliver Vogel",
|
||||
"email": "oliver@intervention.io",
|
||||
"homepage": "http://intervention.io/"
|
||||
}
|
||||
],
|
||||
"description": "Caching extension for the Intervention Image Class",
|
||||
"homepage": "https://image.intervention.io",
|
||||
"keywords": [
|
||||
"cache",
|
||||
"gd",
|
||||
"image",
|
||||
"imagick",
|
||||
"laravel"
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/Intervention/imagecache/issues",
|
||||
"source": "https://github.com/Intervention/imagecache/tree/2.5.2"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
"url": "https://paypal.me/interventionio",
|
||||
"type": "custom"
|
||||
},
|
||||
{
|
||||
"url": "https://github.com/Intervention",
|
||||
"type": "github"
|
||||
}
|
||||
],
|
||||
"time": "2022-01-22T11:14:47+00:00"
|
||||
},
|
||||
{
|
||||
"name": "laravel/breeze",
|
||||
"version": "v1.8.2",
|
||||
@@ -3565,6 +3632,71 @@
|
||||
},
|
||||
"time": "2021-11-30T19:35:32+00:00"
|
||||
},
|
||||
{
|
||||
"name": "opis/closure",
|
||||
"version": "3.6.3",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/opis/closure.git",
|
||||
"reference": "3d81e4309d2a927abbe66df935f4bb60082805ad"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/opis/closure/zipball/3d81e4309d2a927abbe66df935f4bb60082805ad",
|
||||
"reference": "3d81e4309d2a927abbe66df935f4bb60082805ad",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": "^5.4 || ^7.0 || ^8.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"jeremeamia/superclosure": "^2.0",
|
||||
"phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0 || ^8.0 || ^9.0"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "3.6.x-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"files": [
|
||||
"functions.php"
|
||||
],
|
||||
"psr-4": {
|
||||
"Opis\\Closure\\": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Marius Sarca",
|
||||
"email": "marius.sarca@gmail.com"
|
||||
},
|
||||
{
|
||||
"name": "Sorin Sarca",
|
||||
"email": "sarca_sorin@hotmail.com"
|
||||
}
|
||||
],
|
||||
"description": "A library that can be used to serialize closures (anonymous functions) and arbitrary objects.",
|
||||
"homepage": "https://opis.io/closure",
|
||||
"keywords": [
|
||||
"anonymous functions",
|
||||
"closure",
|
||||
"function",
|
||||
"serializable",
|
||||
"serialization",
|
||||
"serialize"
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/opis/closure/issues",
|
||||
"source": "https://github.com/opis/closure/tree/3.6.3"
|
||||
},
|
||||
"time": "2022-01-27T09:35:39+00:00"
|
||||
},
|
||||
{
|
||||
"name": "overtrue/flysystem-cos",
|
||||
"version": "5.0.1",
|
||||
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user