定制 joppuyo/jpeg-xl-encode 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

joppuyo/jpeg-xl-encode

Composer 安装命令:

composer require joppuyo/jpeg-xl-encode

包简介

A PHP library for encoding JPEG XL images. Very much inspired by WebP Convert.

README 文档

README

JPEG XL Encode

GitHub Workflow Status Packagist Version codecov Packagist PHP Version Support Packagist License REUSE status Active Development

A PHP library for encoding JPEG XL images. Supports JPEG and PNG input. Very much inspired by the excellent WebP Convert library.

It is intended as a plug-and-play solution that covers the most common use cases and it can be used in a wide variety of PHP projects.

Requirements

  • PHP 7.2.5 or later.
  • Linux, macOS or Windows OS
  • One or more of the following methods of encoding JPEG XL images needs to be available:
    • The proc_open PHP function needs to be enabled so the library can execute the cjxl binary on the command line.
    • The vips PHP extension is installed and enabled. VIPS image processing library must be compiled with jxl support
    • The imagick PHP extension is installed and enabled. ImageMagick library needs to be compiled with jxl support

Installation

composer require joppuyo/jpeg-xl-encode

Usage

require __DIR__ . '/vendor/autoload.php';

$source = '/absolute/path/to/source.jpeg';
$destination = '/absolute/path/to/destination.jxl';
$options = [
    'encoding' => 'lossy',
    'quality' => 80,
];
try {
    \NPX\JpegXlEncode\Encoder::encode($source, $destination, $options);
} catch (Exception $exception) {
    error_log('Whoops, something went wrong.');
}

Options

Encoding

encoding

Selects which encoding to use, lossy for VarDCT and lossless for Modular. Default is lossy for JPEG input and lossless for PNG input.

Quality

quality

Image quality for lossy compression. The quality range goes from 1 to 100. Default is 85.

Effort

effort

Controls how much time is used for image encoding. Longer encoding time means smaller files. Range is from 1 to 9 where 1 is the fastest and 9 is the slowest. Default is 7.

Progressive

progressive

Enables progressive decoding for the image. If a web browser supports progressive rendering, the image will download perceptually faster. In VarDCT mode, progressive decoding does not affect the file size much.

Enabling progressive decoding for Modular images is not recommended since it makes the resulting image file significantly larger. It could be enabled at a later date in a future version when there are browsers that support downloading only part of a modular progressive file.

Default value is true for lossy and false for lossless.

Methods

There are four different methods you can use: cjxl binary, cjxl system binary, ImageMagick extension and Vips extension. The library goes through each of the available methods and tries to use them. If none of the methods are available, an exception will be thrown.

Cjxl binary

This method executes the cjxl binary on the command line. It's the most compatible method and it supports the most features. However, the proc_open function needs to be enabled in the PHP installation since the library executes the binary on the command line. Some web hosts may disable this function for security reasons.

Note: this library comes bundled with statically compiled version of the cjxl binary for Linux, macOS and Windows systems. The binary is bundled with all the required libraries which means it will work out of the box without the need to install any additional dependencies.

Cjxl system binary

This is the same as the previous method but it executes the cjxl binary from system PATH. This means you need to install jpeg xl using your system package manager like homebrew or build jpeg xl from source and add the cjxl binary to your PATH variable.

ImageMagick extension

This method uses the ImageMagick library and its PHP extension Imagick. However, ImageMagick needs to be built with JXL delegate. In practice, this means you will need to install the libjxl library on the server. Then you will need to build ImageMagick from the source with the option --with-jxl=yes. Lastly, you will need to install the Imagick PHP extension. The ImageMagick extension does not support progressive encoding at the time. For an example how to compile ImageMagick with JPEG XL support, see this Dockerfile.

Vips extension

This method uses the vips library and its PHP extension. However, vips needs to be built with JXL support. In practice, this means you will need to install the libjxl library on the server. Then you will need to build vips from the source. Lastly, you will need to install the vips PHP extension. The vips extension does not support progressive encoding at the time. For an example how to compile VIPS with JPEG XL support, see this Dockerfile.

In addition the vips extension, you will also need to install the jcupitt/vips PHP library in your project in addition jpeg-xl-encode, you can do this by using the following command:

composer require jcupitt/vips

License

MIT.

For detailed license information, see the individual file headers and .reuse/dep5.

Maintance level

This project is under active development and it has a number of features currently under development.

joppuyo/jpeg-xl-encode 适用场景与选型建议

joppuyo/jpeg-xl-encode 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 39 次下载、GitHub Stars 达 19, 最近一次更新时间为 2021 年 08 月 30 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 joppuyo/jpeg-xl-encode 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 39
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 19
  • 点击次数: 16
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 19
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-08-30