jimp icon indicating copy to clipboard operation
jimp copied to clipboard

File Size Issue

Open piyushkantm opened this issue 5 years ago • 5 comments

Expected Behavior

If any transformation/process has not been perform on image, it should not change image size

Current Behavior

If i init Jimp with a URL and write it to filesystem.. The written file far exceeds the original file size.. mostly > 3 times.

Failure Information (for bugs)

Screenshot 2019-05-10 at 3 19 50 AM

Steps to Reproduce

Run the code


    const _image = await Jimp.read("https://www.artsupplies.co.uk/blog/wp-content/uploads/2019/02/Block-in-768x1024.jpg");

    await _image.writeAsync("test.jpg");

Context

There is a bigger problem. Let's suppose i want to crop a 1024x768 image to 1000x768. if the original file size is 100KB, the output file should be <100KB or worst be few KBs over 100KB not become 4-5 times that of 100KB if i am performing a basic operation such as crop.

  • Jimp Version: 0.6.4
  • Operating System: Mac OSX 10.14.4 (18E226)
  • Node version: v10.15.3

piyushkantm avatar May 09 '19 21:05 piyushkantm

@piyushkantm, can you try with different quality settings and see if that gets you a smaller file size? https://github.com/oliver-moran/jimp/tree/master/packages/jimp#png-and-jpeg-quality.

mkondel avatar May 20 '19 14:05 mkondel

I've tried jpeg jpg quality from 0 to 100 in steps of 10, but there was no difference in output size at all.

However, regardless of the output quality, if i import a jpg image and export it as is without performing any operation on it.. Shouldn't it be intact? Or am i missing something here?

piyushkantm avatar May 21 '19 13:05 piyushkantm

Strange, when I use the quality method in my flow, the file size changes dramatically. Here is my code:

const { Body: fileIn } = await s3.getObject(getInputFileParams).promise()
const image = await Jimp.read(fileIn)
const imageData = await image
  .blit(overlay, 0, height - size)
  .quality(10)
  .getBufferAsync(Jimp.AUTO)

With it set to 10 I get 100kb, without quality at all I get 900kb.

mkondel avatar May 21 '19 14:05 mkondel

I can attest to this.

Just reading the file alone with jimp i.e. Jimp.read(file) is around 3 times bigger than just a fs.statSync.

But I do get file size reductions if I use .quality with a small number (like 10), but if you do .quality(90).write(), it will actually be a larger file.

example here: https://codesandbox.io/s/delicate-feather-yy6il

A-ZC-Lau avatar Jul 04 '19 00:07 A-ZC-Lau

I have the same issue, is there any other method , only set quality low quality function does not work at all ,hehe

I found that ,when use quality,use Jimp.MIME_JPEG mimetype can cut down the file size ,my pictures are png

minggangLu avatar Nov 10 '23 02:11 minggangLu

We've made it easier to access export options for file types better

If you want more accurate image codecs please use the WASM ones. The exact issue here is probably an issue with one of the default JS based codecs.

hipstersmoothie avatar Sep 07 '24 21:09 hipstersmoothie