修改图片上传问题

This commit is contained in:
邹景立 2021-05-13 16:43:53 +08:00
parent dec53f9ca9
commit 7ae13e77a7
5 changed files with 27 additions and 21 deletions

View File

@ -32,7 +32,7 @@ private static $installed = array (
'aliases' => 'aliases' =>
array ( array (
), ),
'reference' => 'f00305015a80eabe31474a75c9147214cb9d8585', 'reference' => 'dec53f9ca9b07c3d9ce31ddaf6553b7c98c22389',
'name' => 'zoujingli/thinkadmin', 'name' => 'zoujingli/thinkadmin',
), ),
'versions' => 'versions' =>
@ -171,7 +171,7 @@ private static $installed = array (
array ( array (
0 => '9999999-dev', 0 => '9999999-dev',
), ),
'reference' => '202f84ff3aabdc4cde3f8d1f0933a05cdd4d7172', 'reference' => 'aaeb9dc81e7e93b6476460a9f58e752aa1e5f3ac',
), ),
'zoujingli/thinkadmin' => 'zoujingli/thinkadmin' =>
array ( array (
@ -180,7 +180,7 @@ private static $installed = array (
'aliases' => 'aliases' =>
array ( array (
), ),
'reference' => 'f00305015a80eabe31474a75c9147214cb9d8585', 'reference' => 'dec53f9ca9b07c3d9ce31ddaf6553b7c98c22389',
), ),
'zoujingli/wechat-developer' => 'zoujingli/wechat-developer' =>
array ( array (

View File

@ -849,12 +849,12 @@
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/zoujingli/ThinkLibrary.git", "url": "https://github.com/zoujingli/ThinkLibrary.git",
"reference": "202f84ff3aabdc4cde3f8d1f0933a05cdd4d7172" "reference": "aaeb9dc81e7e93b6476460a9f58e752aa1e5f3ac"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/202f84ff3aabdc4cde3f8d1f0933a05cdd4d7172", "url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/aaeb9dc81e7e93b6476460a9f58e752aa1e5f3ac",
"reference": "202f84ff3aabdc4cde3f8d1f0933a05cdd4d7172", "reference": "aaeb9dc81e7e93b6476460a9f58e752aa1e5f3ac",
"shasum": "", "shasum": "",
"mirrors": [ "mirrors": [
{ {
@ -871,7 +871,7 @@
"ext-mbstring": "*", "ext-mbstring": "*",
"topthink/framework": "^6.0" "topthink/framework": "^6.0"
}, },
"time": "2021-05-12T08:50:33+00:00", "time": "2021-05-13T08:42:48+00:00",
"default-branch": true, "default-branch": true,
"type": "library", "type": "library",
"extra": { "extra": {

View File

@ -6,7 +6,7 @@
'aliases' => 'aliases' =>
array ( array (
), ),
'reference' => 'f00305015a80eabe31474a75c9147214cb9d8585', 'reference' => 'dec53f9ca9b07c3d9ce31ddaf6553b7c98c22389',
'name' => 'zoujingli/thinkadmin', 'name' => 'zoujingli/thinkadmin',
), ),
'versions' => 'versions' =>
@ -145,7 +145,7 @@
array ( array (
0 => '9999999-dev', 0 => '9999999-dev',
), ),
'reference' => '202f84ff3aabdc4cde3f8d1f0933a05cdd4d7172', 'reference' => 'aaeb9dc81e7e93b6476460a9f58e752aa1e5f3ac',
), ),
'zoujingli/thinkadmin' => 'zoujingli/thinkadmin' =>
array ( array (
@ -154,7 +154,7 @@
'aliases' => 'aliases' =>
array ( array (
), ),
'reference' => 'f00305015a80eabe31474a75c9147214cb9d8585', 'reference' => 'dec53f9ca9b07c3d9ce31ddaf6553b7c98c22389',
), ),
'zoujingli/wechat-developer' => 'zoujingli/wechat-developer' =>
array ( array (

2
vendor/services.php vendored
View File

@ -1,5 +1,5 @@
<?php <?php
// This file is automatically generated at:2021-05-12 17:07:00 // This file is automatically generated at:2021-05-13 16:43:36
declare (strict_types = 1); declare (strict_types = 1);
return array ( return array (
0 => 'think\\admin\\Library', 0 => 'think\\admin\\Library',

View File

@ -63,11 +63,11 @@ class ImageExtend
*/ */
private function _openImage(): array private function _openImage(): array
{ {
[$width, $height, $type, $attr] = getimagesize($this->src); [$width, $height, $type] = getimagesize($this->src);
if ($width < 1 || $height < 1) return [0, '读取图片尺寸失败!']; if ($width < 1 || $height < 1) return [0, '读取图片尺寸失败!'];
$this->imageinfo = ['width' => $width, 'height' => $height, 'attr' => $attr, 'type' => image_type_to_extension($type, false)]; $this->imageinfo = ['width' => $width, 'height' => $height, 'type' => image_type_to_extension($type, false)];
$fun = "imagecreatefrom{$this->imageinfo['type']}"; $fun = "imagecreatefrom{$this->imageinfo['type']}";
$this->image = $fun($this->src); imagealphablending($this->image = $fun($this->src), true);
return $this->_thumpImage(); return $this->_thumpImage();
} }
@ -76,13 +76,19 @@ class ImageExtend
*/ */
private function _thumpImage(): array private function _thumpImage(): array
{ {
$newWidth = intval($this->imageinfo['width'] * $this->percent); [$srcWidth, $srcHeight] = [$this->imageinfo['width'], $this->imageinfo['height']];
$newHeight = intval($this->imageinfo['height'] * $this->percent); [$newWidth, $newHeight] = [intval($srcWidth * $this->percent), intval($srcHeight * $this->percent)];
$imgThumps = imagecreatetruecolor($newWidth, $newHeight); [$srcThumps, $dstBackup] = [imagecreatetruecolor($newWidth, $newHeight), imagecreatetruecolor($srcWidth, $srcHeight)];
// 将原图复制带图片载体上面,并且按照一定比例压缩,极大的保持了清晰度
imagecopyresampled($imgThumps, $this->image, 0, 0, 0, 0, $newWidth, $newHeight, $this->imageinfo['width'], $this->imageinfo['height']); [imagealphablending($srcThumps, false), imagesavealpha($srcThumps, true)];
imagedestroy($this->image); [imagealphablending($dstBackup, false), imagesavealpha($dstBackup, true)];
$this->image = $imgThumps;
imagecopyresampled($srcThumps, $this->image, 0, 0, 0, 0, $newWidth, $newHeight, $srcWidth, $srcHeight);
imagecopyresampled($dstBackup, $srcThumps, 0, 0, 0, 0, $srcWidth, $srcHeight, $newWidth, $newHeight);
[imagedestroy($srcThumps), imagedestroy($this->image)];
$this->image = $dstBackup;
return [1, '图片压缩成功']; return [1, '图片压缩成功'];
} }