What is jpegtran-bin?
jpegtran-bin is an npm package that provides a binary wrapper for jpegtran, a command-line utility for optimizing JPEG images. It allows you to perform various operations on JPEG files such as lossless compression, cropping, and rotation.
What are jpegtran-bin's main functionalities?
Lossless Compression
This feature allows you to optimize JPEG images without losing quality. The code sample demonstrates how to use jpegtran-bin to perform lossless compression on an input JPEG file and save the optimized image as output.jpg.
const execFile = require('child_process').execFile;
const jpegtran = require('jpegtran-bin');
execFile(jpegtran, ['-optimize', '-outfile', 'output.jpg', 'input.jpg'], err => {
if (err) {
throw err;
}
console.log('Image optimized');
});
Cropping
This feature allows you to crop a JPEG image. The code sample demonstrates how to use jpegtran-bin to crop a 100x100 pixel area from the input image starting at coordinates (10, 10) and save the cropped image as output.jpg.
const execFile = require('child_process').execFile;
const jpegtran = require('jpegtran-bin');
execFile(jpegtran, ['-crop', '100x100+10+10', '-outfile', 'output.jpg', 'input.jpg'], err => {
if (err) {
throw err;
}
console.log('Image cropped');
});
Rotation
This feature allows you to rotate a JPEG image. The code sample demonstrates how to use jpegtran-bin to rotate the input image by 90 degrees and save the rotated image as output.jpg.
const execFile = require('child_process').execFile;
const jpegtran = require('jpegtran-bin');
execFile(jpegtran, ['-rotate', '90', '-outfile', 'output.jpg', 'input.jpg'], err => {
if (err) {
throw err;
}
console.log('Image rotated');
});
Other packages similar to jpegtran-bin
imagemin-jpegtran
imagemin-jpegtran is a plugin for imagemin that uses jpegtran to optimize JPEG images. It offers similar functionalities to jpegtran-bin but is designed to be used within the imagemin ecosystem, which provides a broader range of image optimization tools.
jpegoptim-bin
jpegoptim-bin is an npm package that provides a binary wrapper for jpegoptim, another command-line utility for optimizing JPEG images. It offers similar functionalities to jpegtran-bin, such as lossless compression and optimization, but uses a different underlying tool.
mozjpeg
mozjpeg is an npm package that provides a binary wrapper for MozJPEG, a JPEG encoder that aims to improve JPEG compression while maintaining compatibility with the JPEG standard. It offers advanced compression techniques and can achieve smaller file sizes compared to jpegtran-bin.
jpegtran-bin
libjpeg-turbo is a derivative of libjpeg that uses SIMD instructions (MMX, SSE2, NEON) to accelerate baseline JPEG compression and decompression on x86, x86-64, and ARM systems. On such systems, libjpeg-turbo is generally 2-4x as fast as the unmodified version of libjpeg, all else being equal.
Install
$ npm install --save jpegtran-bin
Usage
var execFile = require('child_process').execFile;
var jpegtran = require('jpegtran-bin').path;
execFile(jpegtran, ['-outfile', 'output.jpg', 'input.jpg'], function (err) {
if (err) {
throw err;
}
console.log('Image minified!');
});
CLI
$ npm install --global jpegtran-bin
$ jpegtran --help
License
MIT © imagemin