Research
Security News
Threat Actor Exposes Playbook for Exploiting npm to Build Blockchain-Powered Botnets
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
imagemin-jpegtran
Advanced tools
The imagemin-jpegtran npm package is a plugin for the imagemin image optimization tool that specifically optimizes JPEG images using jpegtran. It is used to compress JPEG images without losing quality, making it ideal for web developers looking to reduce image file sizes for faster loading times.
Basic JPEG Optimization
This feature allows you to optimize JPEG images in a specified directory and output the optimized images to another directory. The code sample demonstrates how to use imagemin-jpegtran to compress JPEG images in the 'images' folder and save the optimized images in the 'output' folder.
const imagemin = require('imagemin');
const imageminJpegtran = require('imagemin-jpegtran');
(async () => {
await imagemin(['images/*.jpg'], {
destination: 'output',
plugins: [
imageminJpegtran()
]
});
console.log('Images optimized');
})();
Progressive JPEG Optimization
This feature allows you to create progressive JPEGs, which are images that load in successive waves of detail, improving the user experience on slow connections. The code sample shows how to enable the progressive option in imagemin-jpegtran.
const imagemin = require('imagemin');
const imageminJpegtran = require('imagemin-jpegtran');
(async () => {
await imagemin(['images/*.jpg'], {
destination: 'output',
plugins: [
imageminJpegtran({ progressive: true })
]
});
console.log('Images optimized');
})();
JPEG Optimization with Arithmetic Coding
This feature allows you to use arithmetic coding for JPEG compression, which can result in smaller file sizes compared to Huffman coding. The code sample demonstrates how to enable arithmetic coding in imagemin-jpegtran.
const imagemin = require('imagemin');
const imageminJpegtran = require('imagemin-jpegtran');
(async () => {
await imagemin(['images/*.jpg'], {
destination: 'output',
plugins: [
imageminJpegtran({ arithmetic: true })
]
});
console.log('Images optimized');
})();
imagemin-mozjpeg is another plugin for imagemin that optimizes JPEG images using the mozjpeg encoder. It often achieves better compression rates than jpegtran, but it may be slower. It is suitable for scenarios where achieving the smallest possible file size is more important than the speed of compression.
jpegoptim-bin is a Node.js wrapper for jpegoptim, a command-line tool for optimizing JPEG files. It provides similar functionality to imagemin-jpegtran but can be used independently of imagemin. It offers various optimization options, including lossless and lossy compression.
jpeg-recompress-bin is a Node.js wrapper for jpeg-recompress, a tool that optimizes JPEGs using various compression algorithms. It aims to provide the best possible quality-to-size ratio and offers more advanced options for fine-tuning the compression process compared to imagemin-jpegtran.
jpegtran imagemin plugin
$ npm install --save imagemin-jpegtran
var Imagemin = require('imagemin');
var jpegtran = require('imagemin-jpegtran');
var imagemin = new Imagemin()
.src('images/*.jpg')
.dest('build/images')
.use(jpegtran());
imagemin.run(function (err, files) {
if (err) {
throw err;
}
console.log('Files optimized successfully!');
});
You can also use this plugin with gulp:
var gulp = require('gulp');
var jpegtran = require('imagemin-jpegtran');
gulp.task('default', function () {
return gulp.src('images/*.jpg')
.pipe(jpegtran())
.pipe(gulp.dest('build/images'));
});
Type: Boolean
Default: false
Lossless conversion to progressive.
MIT © imagemin
FAQs
jpegtran imagemin plugin
The npm package imagemin-jpegtran receives a total of 211,715 weekly downloads. As such, imagemin-jpegtran popularity was classified as popular.
We found that imagemin-jpegtran demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
Security News
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
Security News
Research
A malicious npm package disguised as a WhatsApp client is exploiting authentication flows with a remote kill switch to exfiltrate data and destroy files.