jpegtran_ffi 0.1.1 copy "jpegtran_ffi: ^0.1.1" to clipboard
jpegtran_ffi: ^0.1.1 copied to clipboard

Mostly lossless transformations of JPEG images, implemented using libjpeg-turbo via Dart's FFI.

jpegtran_ffi #

Mostly lossless transformations of JPEG images, similar to those than can be made using jpegtran tool, e.g. cropping and rotations. Since JPEG data doesn't need to be decoded or encoded it should hopefully be fast as well.

A lossy recompress method to reduce quality & optionally resize has also been added. Resizing is done by libjpeg-turbo during decompression so it should be fast, but a limited set of scaling factors are supported (including 1/2, 1/4, 1/8). EXIF data can be copied from the original image.

This package uses libjpeg-turbo via Dart's FFI. Unlike platform plugins it should be usable from within isolates.

Example #

void cropToSquareAndRotate() {
    var jpegtran = JpegTransformer(_imageBytes);
    try {
        var info = jpegtran.getInfo();

        var cropSize = min(info.width, info.height);
        var crop = JpegCrop(
            w: cropSize,
            h: cropSize,
            x: (info.width - cropSize) ~/ 2,
            y: (info.height - cropSize) ~/ 2,
            alignIfRequired: true,
        );

        var rotate = JpegRotation(
            angle: 90,
            crop: crop,
            options: JpegOptions(grayscale: false),
        );

        var newImage = jpegtran.transform(rotate);
        setState(() {
            _imageBytes = newImage;
        });
    } catch (err) {
        _showError(err, context);
    } finally {
        jpegtran.dispose();
    }
}
Uint8List recompress(Uint8List jpegBytes) {
  var jpegtran = JpegTransformer(jpegBytes);
  try {
    return jpegtran.recompress(
      scale: 0.25,
      quality: 70,
      preserveEXIF: true,
    );
  } finally {
    jpegtran.dispose();
  }
}

TODO #

  • Remove unneeded parts of libjpeg-turbo

License #

jpegtran_ffi code is licensed under the 3-Clause BSD License. Please do note that it is a wrapper around libjpeg-turbo - so please see its license

4
likes
130
pub points
14%
popularity

Publisher

unverified uploader

Mostly lossless transformations of JPEG images, implemented using libjpeg-turbo via Dart's FFI.

Repository
View/report issues

Documentation

API reference

License

BSD-3-Clause (LICENSE)

Dependencies

ffi, flutter

More

Packages that depend on jpegtran_ffi