freshleafmedia/image-compression-finder
Composer 安装命令:
composer require freshleafmedia/image-compression-finder
包简介
README 文档
README
Automatic detection of maximum compression without visually changing the image.
Overview
This is a library which attempts to determine the maximum amount of compression which can be applied to an image while not introducing any visible changes.
The output is an integer between 0 and 100.
Installation
composer require freshleafmedia/image-compression-finder
DSSIM
A working copy of kornelski/dssim must be installed.
To install the latest, at time of writing, on Ubuntu the following one-liner can be used:
curl -sSL https://github.com/kornelski/dssim/releases/download/3.2.3/dssim_3.2.3_amd64.deb > /tmp/dssim.deb && apt install /tmp/dssim.deb
Imagick/GD
Either of Imagick or GD extensions are required.
Usage
use FreshleafMedia\ImageCompressionFinder\ImageCompressionFinder; $quality = ImageCompressionFinder::make()->run('/path/to/image'); $quality; // 66 (0-100)
How it works
The algorithm uses a binary search to repeatedly compress and test an image until the ideal quality is found
- Compress the image with a quality setting of 60
- Analyse the new image using DSSIM
- If the change is within tolerance the quality is halved, if not it is increased by 50% (aka a binary search)
- Compress the image again with the new quality
- GOTO 2
Options
There are a couple of configuration options:
$quality = ImageCompressionFinder::make() ->maxDifference(0.001) // The highest acceptable visual change. 0-∞ where 0 is no change at all ->startingQuality(60) // Where to start the search ->driver('imagick') // The driver to use to compress images. Eg imagick or gd ->run();
Tests
Unit tests can be run via composer test
License
See LICENSE
freshleafmedia/image-compression-finder 适用场景与选型建议
freshleafmedia/image-compression-finder 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.01k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2022 年 12 月 11 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 freshleafmedia/image-compression-finder 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 freshleafmedia/image-compression-finder 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 2.01k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 17
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-12-11