ronpearl/image-compress
Composer 安装命令:
composer require ronpearl/image-compress
包简介
Allows you to utilize Image Magick in order to compress images as needed.
README 文档
README
Symfony package that will allow you to compress image files using Image Magick
NOTE: This is my first attempt at creating a package for packagist. Please feel free to submit any questions or concerns so I can address them accordingly.
Getting Started
This program requires that you have PHP version 5.6.38 or higher and have Image Magick installed. You would need to confirm this in your phpinfo file, it would be listed under the section called "imagick".
It also assumes that you are using composer and you have a composer.json file already. You can either add this to your require section:
{
"require": {
"rpearl/image-compress": ">1.0.0"
}
}
or you can run the composer command to install the package:
composer require pearl/image-compress
and then run:
composer update
Usage
Once the package is installed, you can use it within your classes. Add the statement:
use ImageCompress\Compress;
This will then allow you to call the Compress class and start using the program. Here is a sample using an image URL:
$imageCompress = new Compress();
$compressionResults = $imageCompress->doImageCompression( "http://location/of/imagefile.jpg", FALSE);
dump( $compressionResults );
When creating an instance of the Compress() class, you can pass some variables to customize your compressions. The first variable would be an array of trusted domains (google.com, bing.com, etc...). This way you can limit what domain(s) any compressed image can originate from. The second and third are the compression values based upon Image Magick compression settings. They are based upon images that are either smaller than 800px wide or larger. Both have their own compression values.
Here is a line showing the construction method for Compress():
public function __construct($trustedDomains = [], $smCompressionVal = 75, $lrgCompressionVal = 35)
Once this is set, you can call the doImageCompression() method. This is what allows you to one-by-one compress and receive values back for the final compressed file. The variables are ($originalFileUrlOrPath, $localFile = true, and $getBase64 = false).
$originalFileUrlOrPath is the image URL or the local path to the image.
$localFile defaults to true, but this sets whether the image is from a URL or from a local file.
$getBase64 defaults to false, but you can set it to true if you would like to get the base64 results of the compressed file as well.
Resulting Image(s)
The final images will be saved within your "web" directory under the folder "imageCompress". These folders will be created after your first run of the program. There will be 2 other folders under that: compressed and originals. The originals will temporarily hold the original files, and then the compressed images will be saved into the compressed folder for use later.
Example
Youc an view the example.php file for a raw usage of the package.
ronpearl/image-compress 适用场景与选型建议
ronpearl/image-compress 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 18 次下载、GitHub Stars 达 0, 最近一次更新时间为 2017 年 06 月 30 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 ronpearl/image-compress 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 ronpearl/image-compress 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 18
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 8
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-06-30