Lower quality no difference in file size
See original GitHub issueHi, we are using AWS Lambda@Edge to compress and resize images on the fly, I saw that the compression for jpeg’s wasn’t no where near fully compressed by default so I added the following options. requiredFormat
can be either webp
or jpeg
.
I tested with quality 56 first and then 25 but it made no difference in file size for an original image that is 30 MB (6000x600 px), resized down to 1920 px. Both files were 861 KB…
const Sharp = require('sharp');
// ...
S3.getObject(s3Params).promise()
// perform the resize operation
.then(data => Sharp(data.Body)
.resize({
width: width,
withoutEnlargement: true,
quality: 25,
progressive: false, // jpeg option
optimiseScans: false, // jpeg, required mozjpeg support
chromaSubsampling: '4:4:4', // jpeg
trellisQuantisation: true, // jpeg, required mozjpeg support
overshootDeringing: true, // jpeg, required mozjpeg support
// lossless: true, // webp option
})
.toFormat(requiredFormat)
.toBuffer()
)
.then(buffer => {
S3.putObject({
Body: buffer,
Bucket: s3_bucket,
ContentType: contentType,
CacheControl: 'private, max-age=31536000',
Key: key,
StorageClass: 'STANDARD',
})
According to https://tinyjpg.com/ it can compress the image 45% further and the image afterwards looks perfect…
Some options state in the documentation that they require mozjpeg, how do I know if it’s installed on Lambda@Edge?
Using:
"sharp": {
"version": "0.21.3",
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
How do I reduce the file size of an image?
The primary way to reduce the file size of an image is by increasing the amount of compression. In most image editing applications...
Read more >Best Way to Reduce Image File Size Without Losing Quality
The article here provides 5 methods on how to reduce image file size without losing quality, using an online image size reducer like...
Read more >The Truth About Image Resolution, File Size and the Web
The idea is that by lowering the resolution, you lower the file size, allowing the image to download faster. And yes, smaller file...
Read more >How To Compress a Video: Lower the Size but Not the Quality
Fortunately, we do have video compression to shrink those file sizes without losing video quality. Here's a primer on how compression works, ...
Read more >Reduce the file size of a picture in Microsoft Office
Change default picture resolution for all pictures in a document · Click the File tab. · Click Options and then click Advanced. ·...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
You’ll need to compile libvips from source with support for mozjpeg and make it available globally. How you do that with Lambda@Edge is a question for AWS to answer or perhaps someone on StackOverflow to help with - good luck!
Seems like they already support
mozjpeg
already because the images becomes much smaller using Lambda than locally where I don’t think I have it installed 😃(but don’t take my word for it)