Security News
npm Updates Search Experience with New Objective Sorting Options
npm has a revamped search experience with new, more transparent sorting options—Relevance, Downloads, Dependents, and Publish Date.
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.
$ npm install imagemin-mozjpeg
import imagemin from 'imagemin';
import imageminMozjpeg from 'imagemin-mozjpeg';
(async () => {
await imagemin(['images/*.jpg'], {
destination: 'build/images',
plugins: [
imageminMozjpeg()
]
});
console.log('Images optimized');
})();
Returns a Promise<Buffer>
.
Type: object
Type: number
Compression quality, in range 0
(worst) to 100
(perfect).
Type: boolean
Default: true
false
creates baseline JPEG file.
Type: boolean
Default: false
Input file is Targa format (usually not needed).
Type: boolean
Default: false
Revert to standard defaults instead of mozjpeg defaults.
Type: boolean
Default: false
Disable progressive scan optimization.
Type: number
Default: 1
Set DC scan optimization mode.
0
One scan for all components1
One scan per component2
Optimize between one scan for all components and one scan for 1st component plus one scan for remaining componentsType: boolean
Default: true
Type: boolean
Default: true
Trellis optimization of DC coefficients.
Type: string
Default: hvs-psnr
Set Trellis optimization method. Available methods: psnr
, hvs-psnr
, ssim
, ms-ssim
Type: boolean
Default: true
Black-on-white deringing via overshoot.
Type: boolean
Default: false
Use arithmetic coding.
Type: string
Default: int
Set DCT method:
int
Use integer DCTfast
Use fast integer DCT (less accurate)float
Use floating-point DCTType: boolean
Default: false
Use 8-bit quantization table entries for baseline JPEG compatibility.
Type: number
Use predefined quantization table.
0
JPEG Annex K1
Flat2
Custom, tuned for MS-SSIM3
ImageMagick table by N. Robidoux4
Custom, tuned for PSNR-HVS5
Table from paper by Klein, Silverstein and CarneyType: number
Set the strength of smooth dithered input. (1...100)
Type: number
Set the maximum memory to use in kilobytes.
Type: string[]
Set component sampling factors. Each item should be in the format HxV
, for example 2x1
.
Type: buffer
Buffer to optimize.
FAQs
Imagemin plugin for mozjpeg
The npm package imagemin-mozjpeg receives a total of 271,234 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.
Security News
npm has a revamped search experience with new, more transparent sorting options—Relevance, Downloads, Dependents, and Publish Date.
Security News
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.