question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Lower quality no difference in file size

See original GitHub issue

Hi, 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:closed
  • Created 5 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
lovellcommented, Mar 21, 2019

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!

0reactions
OZZlEcommented, Mar 21, 2019

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)

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found