Browse Source

图片压缩

master
wanghongjun 2 years ago
parent
commit
8e6d49e069
  1. 22
      app/logic/Upload.php
  2. 3
      composer.json
  3. 86
      composer.lock

22
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;
}
}

3
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",

86
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",

Loading…
Cancel
Save