digitalzenworks/php-image-optimizer
Composer 安装命令:
composer require digitalzenworks/php-image-optimizer
包简介
A responsive image workflow for optimizing and resizing your images
README 文档
README
A responsive image workflow for optimizing and resizing your images. Details can be found in the excellent article at Efficient Image Resizing With ImageMagick
Originally based off (forked) https://github.com/nwtn/php-respimg
Requirements/dependencies
-
Optional: For optimization, depending on what settings you pass:
Installation
Git
git clone https://github.com/jamesjohnmcguire/PhpImageOptimizer
Composer
composer require https://packagist.org/packages/digitalzenworks/php-image-optimizer
Examples
To resize one raster image, without optimization:
$image = new DigitalZenWorks\ImageOptimizer($input_filename); $image->smartResize($output_width, $output_height, false); $image->writeImage($output_filename);
To resize one raster image and maintain aspect ratio, without optimization:
$image = new DigitalZenWorks\ImageOptimizer($input_filename); $image->smartResize($output_width, 0, false); $image->writeImage($output_filename);
To resize one raster image and maintain aspect ratio, with optimization:
$image = new DigitalZenWorks\ImageOptimizer($input_filename); $image->smartResize($output_width, 0, true); $image->writeImage($output_filename); nwtn\Respimg::optimize($output_filename, 0, 1, 1, 1);
To resize a directory of raster images and maintain aspect ratio, with optimization:
$exts = array('jpeg', 'jpg', 'png'); if ($dir = opendir($input_path)) { while (($file = readdir($dir)) !== false) { $base = pathinfo($file, PATHINFO_BASENAME); $ext = strtolower(pathinfo($file, PATHINFO_EXTENSION)); if (in_array($ext, $exts)) { $image = new DigitalZenWorks\ImageOptimizer($input_path . '/' . $file); $image->smartResize($width, 0, true); $image->writeImage($output_path . '/' . $base . '-w' . $w . '.' . $ext); } } } DigitalZenWorks\ImageOptimizer::optimize($output_path, 0, 1, 1, 1);
To resize a directory of raster images and SVGs and maintain aspect ratio, with optimization:
$exts = array('jpeg', 'jpg', 'png'); if ($dir = opendir($input_path)) { while (($file = readdir($dir)) !== false) { $base = pathinfo($file, PATHINFO_BASENAME); $ext = strtolower(pathinfo($file, PATHINFO_EXTENSION)); if (in_array($ext, $exts)) { $image = new DigitalZenWorks\ImageOptimizer($input_path . '/' . $file); $image->smartResize($width, 0, true); $image->writeImage($output_path . '/' . $base . '-w' . $w . '.' . $ext); } elseif ($ext === 'svg') { copy($input_path . '/' . $file, $output_path . '/' . $file); DigitalZenWorks\ImageOptimizer::rasterize($input_path . '/' . $file, $output_path . '/', $width, 0); } } } DigitalZenWorks\ImageOptimizer::optimize($output_path, 3, 1, 1, 1);
Contributing
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature) - Commit your Changes (
git commit -m 'Add some AmazingFeature') - Push to the Branch (
git push origin feature/AmazingFeature) - Open a Pull Request
License
Distributed under the MIT License. See LICENSE for more information.
Contact
James John McGuire - @jamesmc - jamesjohnmcguire@gmail.com
Project Link: https://github.com/jamesjohnmcguire/PhpImageOptimizer
digitalzenworks/php-image-optimizer 适用场景与选型建议
digitalzenworks/php-image-optimizer 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 19 次下载、GitHub Stars 达 1, 最近一次更新时间为 2021 年 11 月 20 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「ImageMagick」 「resize」 「imagick」 「rwd」 「Responsive Images」 「respimg」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 digitalzenworks/php-image-optimizer 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 digitalzenworks/php-image-optimizer 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 digitalzenworks/php-image-optimizer 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Imagemagick wrapper for Symfony
Stand-alone zoomify tile generator (format Zoomify) for use with OpenSeadragon, OpenLayers and various viewers.
Image cache
Image manipulation library for Laravel 8 based on Imagine and inspired by Croppa for easy url based manipulation
The lireincore/imgcache integration for the Yii2 framework
Php library for converting and caching images to Webp .webp, JpegXr .jxr, Jpeg 2000 .jp2
统计信息
- 总下载量: 19
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 10
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-11-20