承接 locomotivemtl/charcoal-image-compression 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

locomotivemtl/charcoal-image-compression

Composer 安装命令:

composer require locomotivemtl/charcoal-image-compression

包简介

Charcoal module to handle image compression through compression api providers

README 文档

README

License Latest Stable Version Build Status

A Charcoal module to handle image compression through compression api providers

Installation

The preferred (and only supported) method is with Composer:

composer require locomotivemtl/charcoal-image-compression

Dependencies

Required

PSR

  • PSR-3: Common interface for logging libraries. Fulfilled by Monolog.
  • PSR-11: Common interface for dependency containers. Fulfilled by Pimple.

Service Provider

The following services are provided with the use of charcoal-image-compression

Services

Configuration

The configuration of the comporession module is done via the modules key of the project configuration. Charcoal image is hooked to use the compression module automatically once configured.

Example: Minimum configuration via image_compression definition
"image_compression": {
    "providers": [/**/]
}
Example: Minimum configuration via modules definition
"modules": {
    "charcoal/image-compression/image-compression": {
        "providers": [/**/]
    }
}
Example: Full configuration via modules definition with default options
"modules": {
    "charcoal/image-compression/image-compression": {
        "registryObject": "charcoal/image-compression/model/registry",
        "batchConfig": {
            "fileExtensions": [ "jpg", "jpeg", "png" ],
            "basePath": "uploads"
        },
        "providers": [/**/]
    }
},

Module Options

Option Type Description Default
autoCompress bool (TODO) Whether to compress files when they are saved in Charcoal. true
registryObject string The registry object to keep track of compression. charcoal/image-compression/model/registry
batchConfig object Options for the batch compression process. n/a
fileExtension string[] List of extensions used with [glob()]. [ "jpg", "jpeg", "png" ]
basePath string The base path to glob from. uploads
providers array[] List of providers with their options. Each provider have it's own set of options to define. []

Providers

The providers key can be used to list and configured some providers that are tasked to bridge the gaps between Charcoal and the different apis. Each providers defines their own options. Here's an example of a provider configuration for tinify provider.

{
    "providers": [
        {
            "type": "tinify",
            "key": "XXXXXX"
        }
    ]
}

Multiple providers can be used at the same time and will be chained one after the other so that if a provider as reached a limit or fails, the next one on the list will be used instead.

List of special providers

Provider Package Features
Chain locomotivemtl/charcoal-image-compression/chain-provider Chaining providers

List of available providers

Provider Package Features
Tinify locomotivemtl/charcoal-image-compression/tinify-provider JPG, PNG, Learn more

Usage

TODO

By default, if provider is defined in the module's configuration, Charcoal image properties will compress the uploaded images on the image save callback. Must use the option autoCompress set to true which is the default behavior.

Script

A script is provided to compress images on the server in a batch.

# Using default path from configuration
vendor/bin/charcoal admin/image-compression/batch-compress

# Using a custom path
vendor/bin/charcoal admin/image-compression/batch-compress --path my/custom/path

Image Compressor

The compression module can also be used as a standalone module via the ImageCompressor class. A container service is provided to access it.

// Fetch image conmpression from pimple container
$this->imageCompressor = $container['image-compressor'];

// The compress method is used to compress a source file path to a target path.
$this->imageCompressor->compress($source, $target)

The ImageCompressor class will use the predefined module configuration and providers. For a custom implementation, instantiate the providers manually

use Charcoal\ImageCompression\Provider\Tinify\TinifyProvider;

$provider = new TinifyProvider([...]);
$provider->compress($source, $target);

// Or use the special Chain Provider to chain providers together

use Charcoal\ImageCompression\Provider\Tinify\TinifyProvider;
use Charcoal\ImageCompression\Provider\Chain\ChainProvider;

$chainProvider = new ChainProvider([
    new TinifyProvider([...])
]);

$chainProvider->compress($source, $target);

Development

To install the development environment:

composer install

To run the scripts (phplint, phpcs, and phpunit):

composer test

API Documentation

Development Dependencies

  • [php-coveralls/php-coveralls][phpcov]
  • [phpunit/phpunit][phpunit]
  • [squizlabs/php_codesniffer][phpcs]

Coding Style

The charcoal-image-compression module follows the Charcoal coding-style:

Coding style validation / enforcement can be performed with composer phpcs. An auto-fixer is also available with composer phpcbf.

Credits

License

Charcoal is licensed under the MIT license. See LICENSE for details.

locomotivemtl/charcoal-image-compression 适用场景与选型建议

locomotivemtl/charcoal-image-compression 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 634 次下载、GitHub Stars 达 2, 最近一次更新时间为 2022 年 03 月 28 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「image」 「compression」 「compress」 「optimization」 「charcoal」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 locomotivemtl/charcoal-image-compression 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 locomotivemtl/charcoal-image-compression 我们能提供哪些服务?
定制开发 / 二次开发

基于 locomotivemtl/charcoal-image-compression 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

  • Stars: 2
  • Watchers: 3
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-03-28