perf: 对webp文件的支持
This commit is contained in:
@@ -2085,7 +2085,7 @@ class Base
|
||||
$imgBase64 = $param['image64'];
|
||||
if (preg_match('/^(data:\s*image\/(\w+);base64,)/', $imgBase64, $res)) {
|
||||
$extension = $res[2];
|
||||
if (!in_array($extension, ['png', 'jpg', 'jpeg', 'gif'])) {
|
||||
if (!in_array($extension, ['png', 'jpg', 'jpeg', 'webp', 'gif'])) {
|
||||
return Base::retError('图片格式错误');
|
||||
}
|
||||
$scaleName = "";
|
||||
@@ -2197,11 +2197,8 @@ class Base
|
||||
case 'png':
|
||||
$type = ['png'];
|
||||
break;
|
||||
case 'png+jpg':
|
||||
$type = ['jpg', 'jpeg', 'png'];
|
||||
break;
|
||||
case 'image':
|
||||
$type = ['jpg', 'jpeg', 'gif', 'png'];
|
||||
$type = ['jpg', 'jpeg', 'webp', 'gif', 'png'];
|
||||
break;
|
||||
case 'video':
|
||||
$type = ['rm', 'rmvb', 'wmv', 'avi', 'mpg', 'mpeg', 'mp4'];
|
||||
@@ -2219,7 +2216,7 @@ class Base
|
||||
$type = ['zip'];
|
||||
break;
|
||||
case 'file':
|
||||
$type = ['jpg', 'jpeg', 'png', 'gif', 'doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', 'txt', 'esp', 'pdf', 'rar', 'zip', 'gz', 'ai', 'avi', 'bmp', 'cdr', 'eps', 'mov', 'mp3', 'mp4', 'pr', 'psd', 'svg', 'tif'];
|
||||
$type = ['jpg', 'jpeg', 'webp', 'png', 'gif', 'doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', 'txt', 'esp', 'pdf', 'rar', 'zip', 'gz', 'ai', 'avi', 'bmp', 'cdr', 'eps', 'mov', 'mp3', 'mp4', 'pr', 'psd', 'svg', 'tif'];
|
||||
break;
|
||||
case 'firmware':
|
||||
$type = ['img', 'tar', 'bin'];
|
||||
@@ -2306,7 +2303,7 @@ class Base
|
||||
}
|
||||
}
|
||||
//
|
||||
if (in_array($extension, ['jpg', 'jpeg', 'gif', 'png'])) {
|
||||
if (in_array($extension, ['jpg', 'jpeg', 'webp', 'gif', 'png'])) {
|
||||
//图片尺寸
|
||||
$paramet = getimagesize($array['file']);
|
||||
$array['width'] = $paramet[0];
|
||||
@@ -2417,7 +2414,7 @@ class Base
|
||||
$dst_img = $src_img;
|
||||
}
|
||||
$st = pathinfo($src_img, PATHINFO_EXTENSION);
|
||||
if (!in_array(strtolower($st), array('jpg', 'jpeg', 'png', 'gif', 'bmp'))) {
|
||||
if (!in_array(strtolower($st), array('jpg', 'jpeg', 'webp', 'png', 'gif', 'bmp'))) {
|
||||
return false;
|
||||
}
|
||||
$ot = pathinfo($dst_img, PATHINFO_EXTENSION);
|
||||
|
||||
@@ -34,7 +34,9 @@ class ImgCompress
|
||||
*/
|
||||
public function compressImg($saveName = '')
|
||||
{
|
||||
$this->_openImage();
|
||||
if (!$this->_openImage()) { //打开图片
|
||||
return;
|
||||
}
|
||||
if (!empty($saveName)) $this->_saveImage($saveName); //保存
|
||||
else $this->_showImage();
|
||||
}
|
||||
@@ -52,8 +54,12 @@ class ImgCompress
|
||||
'attr' => $attr
|
||||
);
|
||||
$fun = "imagecreatefrom" . $this->imageinfo['type'];
|
||||
if (!function_exists($fun)) {
|
||||
return false;
|
||||
}
|
||||
$this->image = $fun($this->src);
|
||||
$this->_thumpImage();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -90,7 +96,7 @@ class ImgCompress
|
||||
if (str_contains($dstImgName, '.')) {
|
||||
$dstName = $dstImgName;
|
||||
} else {
|
||||
$allowImgs = ['.jpg', '.jpeg', '.png', '.bmp', '.wbmp', '.gif']; //如果目标图片名有后缀就用目标图片扩展名 后缀,如果没有,则用源图的扩展名
|
||||
$allowImgs = ['.jpg', '.jpeg', '.webp', '.png', '.bmp', '.wbmp', '.gif']; //如果目标图片名有后缀就用目标图片扩展名 后缀,如果没有,则用源图的扩展名
|
||||
$dstExt = strrchr($dstImgName, ".");
|
||||
$sourseExt = strrchr($this->src, ".");
|
||||
if (!empty($dstExt)) $dstExt = strtolower($dstExt);
|
||||
@@ -105,6 +111,9 @@ class ImgCompress
|
||||
}
|
||||
}
|
||||
$funcs = "image" . $this->imageinfo['type'];
|
||||
if (!function_exists($funcs)) {
|
||||
return false;
|
||||
}
|
||||
$funcs($this->image, $dstName);
|
||||
return true;
|
||||
}
|
||||
@@ -114,7 +123,9 @@ class ImgCompress
|
||||
*/
|
||||
public function __destruct()
|
||||
{
|
||||
imagedestroy($this->image);
|
||||
if ($this->image) {
|
||||
imagedestroy($this->image);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -132,7 +143,7 @@ class ImgCompress
|
||||
if (!file_exists($src)) {
|
||||
return;
|
||||
}
|
||||
$allowImgs = ['.jpg', '.jpeg', '.png', '.bmp', '.wbmp'];
|
||||
$allowImgs = ['.jpg', '.jpeg', '.webp', '.png', '.bmp', '.wbmp'];
|
||||
if (!in_array(strrchr($src, "."), $allowImgs)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user