wad/image-compressor
Composer 安装命令:
composer require wad/image-compressor
包简介
A lightweight PHP package to compress image files (JPEG, PNG, WebP) with adjustable quality or target size. Easily reduce file sizes in your PHP projects using pure GD.
README 文档
README
A lightweight PHP package to compress image files (JPEG, PNG, WebP) with adjustable quality or target size. Easily reduce file sizes in your PHP projects using pure GD.
🚀 Features
- ✅ Compress JPEG, PNG, and WebP images
- ✅ Target compression by percentage or file size (KB)
- ✅ Compress single or multiple images in batch
- ✅ Automatically resizes large images (maintains aspect ratio)
- ✅ Maintains transparency for PNG/WebP
- ✅ Overwrite originals or save to custom folder
- ✅ Pure PHP with GD – no external dependencies
- ✅ Easy integration with Laravel, Symfony, or standalone PHP
⚙️ Requirements
- PHP 7.2 or higher
- GD extension enabled (
ext-gd)
📦 Installation
Install via Composer:
composer require wad/image-compressor:dev-master
✅ Basic Usage
require 'vendor/autoload.php'; use Wad\ImageCompressor\Compressor; // Create compressor with default quality (JPEG: 75, PNG/WebP: 6) $compressor = new Compressor(); // Compress single image by 50% size $original = __DIR__ . '/image.png'; $compressed = __DIR__ . '/image-compressed.png'; $result = $compressor->compressToPercentage($original, $compressed, 0.5); if ($result !== false) { echo "Compressed successfully to $result bytes"; } else { echo "Compression failed"; }
🎯 Compress to Target File Size
$compressor = new Compressor(); $input = __DIR__ . '/banner.jpg'; $output = __DIR__ . '/banner-small.jpg'; // Compress to 300 KB $result = $compressor->compressToSize($input, $output, 300); echo $result ? "Compressed to $result bytes" : "Compression failed";
🗂 Batch Compression (By Percentage)
$files = [ __DIR__ . '/img1.jpg', __DIR__ . '/img2.png', ]; $outputDir = __DIR__ . '/compressed_50'; $results = $compressor->compressMultipleToPercentage($files, $outputDir, 0.5); foreach ($results as $file => $size) { echo basename($file) . ": " . ($size ? "$size bytes" : "Failed") . "\n"; }
📏 Batch Compression (By Target Size)
$files = [ __DIR__ . '/photo1.webp', __DIR__ . '/photo2.png', ]; $outputDir = __DIR__ . '/compressed_300kb'; $results = $compressor->compressMultipleToSize($files, $outputDir, 300); foreach ($results as $file => $size) { echo basename($file) . ": " . ($size ? "$size bytes" : "Failed") . "\n"; }
📝 License
MIT License. See the LICENSE file.
👤 Author We Are Developers 📧 suriyatkms1218.in@gmail.com 🌐 https://suriyadev.in
wad/image-compressor 适用场景与选型建议
wad/image-compressor 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 07 月 29 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「image」 「compression」 「compressor」 「png」 「jpeg」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 wad/image-compressor 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 wad/image-compressor 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 wad/image-compressor 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Asset Management for PHP
Image optimization / compression library. This library is able to optimize png, jpg and gif files in very easy and handy way. It uses optipng, pngquant, pngcrush, pngout, gifsicle, jpegoptim and jpegtran tools.
Yii2 LightBox image galary widget uses Lightbox v2.10.0 by Lokesh Dhakar
The Yii2 extension uses jQuery jquery.carousel-1.1.min.js and makes image carousel from php array of structure defined.
The Yii2 extension uses jQuery PrettyPhoto and OwlCarousel js and makes image galary from php array of structure defined.
Yii2 integration for TinyPng
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 27
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-07-29