Sharp: .extract resulting into bigger file size?

Created on 15 May 2020  路  3Comments  路  Source: lovell/sharp

Are you using the latest version? Is the version currently in use as reported by npm ls sharp the same as the latest version as reported by npm view sharp dist-tags.latest?

npm view sharp dist-tags.latest
0.25.2

What are the steps to reproduce?

I have this image:
https://media.boacausa.net/cdn/l1/img/slider/slide1.jpg
It's a 1920x815 jpeg and the file size is 64.6聽kB.

This results an image of 106聽kB:

const image = sharp(buffer)
  .jpeg({ quality: 80, progressive: true })
  .extract({ width: 1919, height: 815, left: 0, top: 0 })
  .resize({ width: 1920, height: 815 })
  .toBuffer()

This results an image of 78.0聽kB:

const image = sharp(buffer)
  .jpeg({ quality: 80, progressive: true })
  //.extract({ width: 1919, height: 815, left: 0, top: 0 })
  .resize({ width: 1920, height: 815 })
  .toBuffer()

What is the expected behavior?
Why is the image getting bigger and why using extract makes it worse?

What is the output of running npx envinfo --binaries --system?

npx: installed 1 in 2.658s

  System:
    OS: Linux 4.19 Debian GNU/Linux 9 (stretch) 9 (stretch)
    CPU: (4) x64 Intel(R) Core(TM) i5-8279U CPU @ 2.40GHz
    Memory: 5.07 GB / 8.01 GB
    Container: Yes
    Shell: 4.4.12 - /bin/bash
  Binaries:
    Node: 13.12.0 - /usr/local/bin/node
    Yarn: 1.22.4 - /usr/local/bin/yarn
    npm: 6.14.4 - /usr/local/bin/npm

Thanks!

question

All 3 comments

The original image is non-progressive and was saved with a quality setting of approximately 69.

$ identify -verbose slide1.jpg | grep -E 'Quality|Interlace'
  Interlace: No
  JPEG-Quality: 69

@lovell Any idea why using .extract makes it even bigger?

The code sample here will result in upscaling from 1919x815 to 1920x815 so the JPEG encoder is being fed with different pixel values.

Was this page helpful?
0 / 5 - 0 ratings