From 8e6d49e069254f17956818b179d096d046b25847 Mon Sep 17 00:00:00 2001 From: wanghongjun <1445693971@qq,com> Date: Fri, 3 Nov 2023 10:19:03 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9B=BE=E7=89=87=E5=8E=8B=E7=BC=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/logic/Upload.php | 22 +++++++++++- composer.json | 3 +- composer.lock | 86 +++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 108 insertions(+), 3 deletions(-) diff --git a/app/logic/Upload.php b/app/logic/Upload.php index fce6780..c85f840 100644 --- a/app/logic/Upload.php +++ b/app/logic/Upload.php @@ -2,6 +2,7 @@ namespace app\logic; +use Intervention\Image\ImageManagerStatic as Image; use think\facade\Filesystem; class Upload @@ -18,7 +19,7 @@ class Upload // 上传到本地服务器 // $file = request()->file('image'); - return Filesystem::putFile( $path, $file); + return self::compressAndSave(Filesystem::putFile( $path, $file)); } /** @@ -37,4 +38,23 @@ class Upload return $saveName; } + /** + * 图片压缩 + * @param $path + * @return mixed + */ + public static function compressAndSave($path) + { + // 获取根目录 + $rootPath = app()->getRootPath(); + $storage = config('filesystem.disks.public.url'); + // 获取绝对路径 + $absolutePath = $rootPath . 'public/' . "{$storage}/" . $path; + + $image = Image::make($absolutePath); + $image->encode('jpg',10)->save($absolutePath); + + return $path; + } + } \ No newline at end of file diff --git a/composer.json b/composer.json index bb4168f..0d3ba71 100644 --- a/composer.json +++ b/composer.json @@ -28,7 +28,8 @@ "alibabacloud/sdk": "^1.8", "topthink/think-filesystem": "^2.0", "topthink/think-view": "^1.0", - "yansongda/pay": "2.10" + "yansongda/pay": "2.10", + "intervention/image": "^2.7" }, "require-dev": { "symfony/var-dumper": "^4.2", diff --git a/composer.lock b/composer.lock index 36c00a5..863c259 100644 --- a/composer.lock +++ b/composer.lock @@ -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": "1b7895e47b834768c79f1a78d46b7cfd", + "content-hash": "ee4470e36bbcde4db830219247a7f62c", "packages": [ { "name": "adbario/php-dot-notation", @@ -824,6 +824,90 @@ ], "time": "2023-08-03T15:06:02+00:00" }, + { + "name": "intervention/image", + "version": "2.7.2", + "source": { + "type": "git", + "url": "https://github.com/Intervention/image.git", + "reference": "04be355f8d6734c826045d02a1079ad658322dad" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Intervention/image/zipball/04be355f8d6734c826045d02a1079ad658322dad", + "reference": "04be355f8d6734c826045d02a1079ad658322dad", + "shasum": "" + }, + "require": { + "ext-fileinfo": "*", + "guzzlehttp/psr7": "~1.1 || ^2.0", + "php": ">=5.4.0" + }, + "require-dev": { + "mockery/mockery": "~0.9.2", + "phpunit/phpunit": "^4.8 || ^5.7 || ^7.5.15" + }, + "suggest": { + "ext-gd": "to use GD library based image processing.", + "ext-imagick": "to use Imagick based image processing.", + "intervention/imagecache": "Caching extension for the Intervention Image library" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.4-dev" + }, + "laravel": { + "providers": [ + "Intervention\\Image\\ImageServiceProvider" + ], + "aliases": { + "Image": "Intervention\\Image\\Facades\\Image" + } + } + }, + "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": "https://intervention.io/" + } + ], + "description": "Image handling and manipulation library with support for Laravel integration", + "homepage": "http://image.intervention.io/", + "keywords": [ + "gd", + "image", + "imagick", + "laravel", + "thumbnail", + "watermark" + ], + "support": { + "issues": "https://github.com/Intervention/image/issues", + "source": "https://github.com/Intervention/image/tree/2.7.2" + }, + "funding": [ + { + "url": "https://paypal.me/interventionio", + "type": "custom" + }, + { + "url": "https://github.com/Intervention", + "type": "github" + } + ], + "time": "2022-05-21T17:30:32+00:00" + }, { "name": "league/flysystem", "version": "2.5.0",