mirror of
https://github.com/kuaifan/dootask.git
synced 2025-12-12 19:35:50 +00:00
perf: 优化缩略图
This commit is contained in:
parent
6ebca3befa
commit
b8852f821c
@ -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 {
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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 '';
|
||||
}
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
<div class="common-img-update">
|
||||
<div v-if="type !== 'callback'" class="imgcomp-upload-list" v-for="item in uploadList">
|
||||
<template v-if="item.status === 'finished'">
|
||||
<div class="imgcomp-upload-img" v-bind:style="{ 'background-image': 'url(' + __thumb(item.thumb) + ')' }"></div>
|
||||
<div class="imgcomp-upload-img" v-bind:style="{ 'background-image': 'url(' + backgroundImage(item.thumb) + ')' }"></div>
|
||||
<div class="imgcomp-upload-list-cover">
|
||||
<Icon type="ios-eye-outline" @click.native="handleView(item)"></Icon>
|
||||
<Icon type="ios-trash-outline" @click.native="handleRemove(item)"></Icon>
|
||||
@ -373,7 +373,7 @@
|
||||
}
|
||||
},
|
||||
|
||||
__thumb(url) {
|
||||
backgroundImage(url) {
|
||||
if ($A.strExists(url, "?", false)) {
|
||||
return $A.mainUrl(url) + "&__thumb=true";
|
||||
}else{
|
||||
|
||||
@ -480,7 +480,10 @@ export default {
|
||||
},
|
||||
// 获取图片缩略图
|
||||
getPictureThumb(src) {
|
||||
return src + '_thumb.' + src.split('.').pop()
|
||||
if (!/\.(png|jpg|jpeg)$/.test(src)) {
|
||||
return src
|
||||
}
|
||||
return $A.thumbRestore(src) + '_thumb.' + src.split('.').pop()
|
||||
},
|
||||
// 打开图片
|
||||
onViewPicture(currentUrl, type) {
|
||||
|
||||
@ -49,10 +49,10 @@ export default {
|
||||
return {};
|
||||
},
|
||||
|
||||
imageStyle({width, height, ext}, type = 'style') {
|
||||
imageStyle({width, height, thumb}, type = 'style') {
|
||||
if (width && height) {
|
||||
const ratioExceed = $A.imageRatioExceed(width, height, 3)
|
||||
if (['png', 'jpg', 'jpeg'].includes(ext) && ratioExceed > 0) {
|
||||
if (/\.(png|jpg|jpeg)$/.test(thumb) && ratioExceed > 0) {
|
||||
if (width > height) {
|
||||
width = height * ratioExceed;
|
||||
} else {
|
||||
@ -89,9 +89,9 @@ export default {
|
||||
return {};
|
||||
},
|
||||
|
||||
imageSrc({width, height, ext, thumb}) {
|
||||
imageSrc({width, height, thumb}) {
|
||||
const ratioExceed = $A.imageRatioExceed(width, height, 3)
|
||||
if (['png', 'jpg', 'jpeg'].includes(ext) && ratioExceed > 0) {
|
||||
if (/\.(png|jpg|jpeg)$/.test(thumb) && ratioExceed > 0) {
|
||||
thumb = $A.thumbRestore(thumb) + `/crop/ratio:${ratioExceed},percentage:320x0`;
|
||||
}
|
||||
return thumb;
|
||||
|
||||
@ -2874,7 +2874,7 @@ export default {
|
||||
|
||||
case "newTask":
|
||||
let content = $A.formatMsgBasic(this.operateItem.msg.text)
|
||||
content = content.replace(/<img[^>]*?src=(["'])(.*?)(_thumb\.jpg)*\1[^>]*?>/g, `<img src="$2">`)
|
||||
content = content.replace(/<img[^>]*?src=(["'])(.*?)(_thumb\.(png|jpg|jpeg))*\1[^>]*?>/g, `<img src="$2">`)
|
||||
content = content.replace(/<li\s+data-list="checked">/g, `<li class="tox-checklist--checked">`)
|
||||
content = content.replace(/<li\s+data-list="unchecked">/g, `<li>`)
|
||||
content = content.replace(/<ol[^>]*>([\s\S]*?)<\/ol>/g, `<ul class="tox-checklist">$1</ul>`)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user