diff --git a/app/Http/Controllers/Api/SystemController.php b/app/Http/Controllers/Api/SystemController.php index fa3701e37..fd9ca6510 100755 --- a/app/Http/Controllers/Api/SystemController.php +++ b/app/Http/Controllers/Api/SystemController.php @@ -984,7 +984,7 @@ class SystemController extends AbstractController ]; // $extension = pathinfo($dirPath . $filename, PATHINFO_EXTENSION); - if (in_array($extension, array('gif', 'jpg', 'jpeg', 'webp', 'png', 'bmp'))) { + if (in_array($extension, ['png', 'jpg', 'jpeg', 'gif', 'webp', 'bmp'])) { if ($extension = Base::getThumbExt($dirPath . $filename)) { $array['thumb'] .= "_thumb.{$extension}"; } else { diff --git a/app/Models/WebSocketDialog.php b/app/Models/WebSocketDialog.php index c0beb8543..18877977a 100644 --- a/app/Models/WebSocketDialog.php +++ b/app/Models/WebSocketDialog.php @@ -716,7 +716,7 @@ class WebSocketDialog extends AbstractModel * * @param User $user 发起会话的会员 * @param array $dialogIds 对话id - * @param file $files 文件对象 + * @param file|mixed $files 文件对象 * @param string $image64 base64文件 * @param string $fileName 文件名称 * @param int $replyId 恢复id diff --git a/app/Module/Base.php b/app/Module/Base.php index 170ff0027..187f0fb12 100755 --- a/app/Module/Base.php +++ b/app/Module/Base.php @@ -2177,19 +2177,10 @@ class Base if ($param['scale'] && is_array($param['scale'])) { list($width, $height) = $param['scale']; if (($width > 0 && $array['width'] > $width) || ($height > 0 && $array['height'] > $height)) { - $cut = ($width > 0 && $height > 0) ? 'cover' : 'percentage'; - $cut = $param['scale'][2] ?? $cut; // 图片裁剪 - $tmpFile = $array['file'] . '_tmp.jpg'; - if (Image::thumbImage($array['file'], $tmpFile, $width, $height, 90, $cut)) { - $tmpSize = filesize($tmpFile); - if ($tmpSize > $fileSize) { - @unlink($tmpFile); - } else { - @unlink($array['file']); - rename($tmpFile, $array['file']); - } - } + $cutMode = ($width > 0 && $height > 0) ? 'cover' : 'percentage'; + $cutMode = $param['scale'][2] ?? $cutMode; + Image::thumbImage($array['file'], $array['file'], $width, $height, 90, $cutMode); // 更新图片尺寸 $paramet = getimagesize($array['file']); $array['width'] = $paramet[0]; @@ -2416,19 +2407,10 @@ class Base if ($param['scale'] && is_array($param['scale'])) { list($width, $height) = $param['scale']; if (($width > 0 && $array['width'] > $width) || ($height > 0 && $array['height'] > $height)) { - $cut = ($width > 0 && $height > 0) ? 'cover' : 'percentage'; - $cut = $param['scale'][2] ?? $cut; // 图片裁剪 - $tmpFile = $array['file'] . '_tmp.jpg'; - if (Image::thumbImage($array['file'], $tmpFile, $width, $height, 90, $cut)) { - $tmpSize = filesize($tmpFile); - if ($tmpSize > $fileSize) { - @unlink($tmpFile); - } else { - @unlink($array['file']); - rename($tmpFile, $array['file']); - } - } + $cutMode = ($width > 0 && $height > 0) ? 'cover' : 'percentage'; + $cutMode = $param['scale'][2] ?? $cutMode; + Image::thumbImage($array['file'], $array['file'], $width, $height, 90, $cutMode); // 更新图片尺寸 $paramet = getimagesize($array['file']); $array['width'] = $paramet[0]; @@ -2517,12 +2499,12 @@ class Base */ public static function getThumbExt($file): string { - if (file_exists($file . '_thumb.jpeg')) { - return 'jpeg'; + if (file_exists($file . '_thumb.png')) { + return 'png'; } elseif (file_exists($file . '_thumb.jpg')) { return 'jpg'; - } elseif (file_exists($file . '_thumb.png')) { - return 'png'; + } elseif (file_exists($file . '_thumb.jpeg')) { + return 'jpeg'; } else { return ''; } diff --git a/app/Module/Image.php b/app/Module/Image.php index e0d8f6384..b2130a678 100644 --- a/app/Module/Image.php +++ b/app/Module/Image.php @@ -240,7 +240,7 @@ class Image if ($quality > 0) { Image::compressImage($savePath, null, $quality); } - if (filesize($savePath) >= filesize($imagePath)) { + if ($savePath != $imagePath && filesize($savePath) >= filesize($imagePath)) { unlink($savePath); symlink(basename($imagePath), $savePath); } diff --git a/resources/assets/js/components/ImgUpload.vue b/resources/assets/js/components/ImgUpload.vue index b08907925..4f904e01a 100755 --- a/resources/assets/js/components/ImgUpload.vue +++ b/resources/assets/js/components/ImgUpload.vue @@ -2,7 +2,7 @@