定制 geckon01/simple-image-compressor 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

geckon01/simple-image-compressor

最新稳定版本:0.4.3.25

Composer 安装命令:

composer require geckon01/simple-image-compressor

包简介

SimpleImageCompressor is a tiny simple PHP image compressor lib which allows you to compress any image easily on the fly

README 文档

README

Version Lecense Downloads Codacy Badge

SimpleImageCompressor - is a tiny simple PHP image resizer lib which allows you to resize and compress any image easily on the fly.

Installation

With composer

composer require "geckon01/simple-image-compressor"

Without composer

  1. Download latest release here.
  2. Unpack the archive to your project directory.
  3. Include the library files:
require "src/SimpleImageCompressor.php";  
require "src/CompressedImage.php";
use geckon01\SimpleImageCompressor\SimpleImageCompressor;

Usage

Resize and compress an image:

$resolutionTargetPercent = 50;
$targetQuality = 50;
$compressor = SimpleImageCompressor::load("image.png");
$compressedImage = $compressor->resizeAndCompress($resolutionTargetPercent, $targetQuality);
$compressedImage->toFile("image");

load method supports loading from local file, or you can specify any valid URL image link like this:

$compressor = SimpleImageCompressor::load("https://example.com/image.jpg");

Method chaining is supported:

SimpleImageCompressor::load("image.png")
	->resizeAndCompress(50, 50)
	->toFile("image");

Note: File extensions are automatically added. Use toFile("filename") without extension.

Output format

You can specify output format. Supported output fomats are:

$compressedImage->toFile("image");
$compressedImage->toBase64();
$compressedImage->toGdImage();

Size Constraints

Set approximate minimum dimensions (aspect ratio preserved):

$compressor->setApproxMinimumHeight(500);  
$compressor->setApproxMinimumWidth(500);

Note actual dimensions may differ due to aspect ratio preservation. Example: 1920×1080 image reduced to 50% becomes 960×540 (maintaining 16:9).

License

This software is licensed under the MIT License. View the license.

统计信息

  • 总下载量: 64
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-03-29