Giter Club home page Giter Club logo

jpeg-xl-encode's Introduction

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.

jpeg-xl-encode's People

Contributors

dependabot[bot] avatar joppuyo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

jpeg-xl-encode's Issues

WebP input

Allow WebP images to be converted into JPEG XL

Auto mode for lossy compression

Add auto mode where both lossy and lossless compression are tried and the smallest file is chosen. This should be the default for JPEG files.

Add some other ways to convert images to JPEG XL

Some ideas inspired by WebP Convert:

  • Web API
  • Imagick/ImageMagick will probably add support at some point
  • In addition to Imagick bindings, support executing the imagemagick binary on the command line
  • GD will probably add support too
  • Add support for finding cjxl binary on the host system
  • PHP FFI?

Timeout setting

Allow setting timeout. This is currently 60 seconds which is symfony/process default.

Stable static binaries

Right now Linux and Windows static binaries are daily builds rather than stable versions. Either wait for JPEG XL to release a new version or build the static binaries from version 0.5.0 source code.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.