Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
imagemin-mozjpeg
Advanced tools
The imagemin-mozjpeg npm package is a plugin for Imagemin that compresses JPEG images using the MozJPEG encoder. It is designed to reduce the file size of JPEG images while maintaining high visual quality, making it ideal for web optimization and other scenarios where image size is a concern.
Basic JPEG Compression
This feature allows you to compress JPEG images using the default settings of the MozJPEG encoder. The code sample demonstrates how to use imagemin-mozjpeg to compress all JPEG images in the 'images' directory and save the optimized images to the 'output' directory.
const imagemin = require('imagemin');
const imageminMozjpeg = require('imagemin-mozjpeg');
(async () => {
await imagemin(['images/*.jpg'], {
destination: 'output',
plugins: [
imageminMozjpeg()
]
});
console.log('Images optimized');
})();
Custom Quality Compression
This feature allows you to specify the quality of the JPEG compression. The code sample demonstrates how to use imagemin-mozjpeg with a custom quality setting of 75, which balances file size and image quality.
const imagemin = require('imagemin');
const imageminMozjpeg = require('imagemin-mozjpeg');
(async () => {
await imagemin(['images/*.jpg'], {
destination: 'output',
plugins: [
imageminMozjpeg({ quality: 75 })
]
});
console.log('Images optimized with custom quality');
})();
Progressive JPEG Compression
This feature enables progressive JPEG compression, which allows images to be displayed incrementally as they are downloaded. The code sample demonstrates how to use imagemin-mozjpeg to compress images with the progressive option enabled.
const imagemin = require('imagemin');
const imageminMozjpeg = require('imagemin-mozjpeg');
(async () => {
await imagemin(['images/*.jpg'], {
destination: 'output',
plugins: [
imageminMozjpeg({ progressive: true })
]
});
console.log('Images optimized with progressive compression');
})();
The imagemin-jpegtran package is another Imagemin plugin that compresses JPEG images using jpegtran. It is known for its lossless compression capabilities, which means it can reduce file size without any loss in image quality. Compared to imagemin-mozjpeg, imagemin-jpegtran is better suited for scenarios where maintaining the original image quality is crucial.
The imagemin-jpegoptim package is an Imagemin plugin that uses jpegoptim for JPEG compression. It offers both lossy and lossless compression options and is highly configurable. Compared to imagemin-mozjpeg, imagemin-jpegoptim provides more flexibility in terms of compression options and is suitable for users who need fine-grained control over the compression process.
The imagemin-webp package is an Imagemin plugin that converts images to the WebP format, which is known for its superior compression and quality characteristics compared to JPEG. While it does not directly compete with imagemin-mozjpeg in terms of JPEG compression, it offers an alternative for users looking to switch to a more modern image format for better performance and quality.
mozjpeg imagemin plugin
$ npm install --save imagemin-mozjpeg
var Imagemin = require('imagemin');
var mozjpeg = require('imagemin-mozjpeg');
var imagemin = new Imagemin()
.src('images/*.jpg')
.dest('build/images')
.use(mozjpeg());
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 mozjpeg = require('imagemin-mozjpeg');
gulp.task('default', function () {
return gulp.src('images/*.jpg')
.pipe(mozjpeg())
.pipe(gulp.dest('build/images'));
});
Type: Boolean
Default: false
Disable progressive scan optimization.
MIT © imagemin
FAQs
Imagemin plugin for mozjpeg
The npm package imagemin-mozjpeg receives a total of 236,799 weekly downloads. As such, imagemin-mozjpeg popularity was classified as popular.
We found that imagemin-mozjpeg demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 7 open source maintainers 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
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.