WangYuLue / image-conversion

A simple and easy-to-use JS image convert tools, which can specify size to compress the image.
https://demo.wangyulue.com/image-conversion/
MIT License
906 stars 139 forks source link

Image cannot be converted accurately to the size #43

Open enjoykcc456 opened 3 years ago

enjoykcc456 commented 3 years ago

Hi, thanks for the library. I have been trying to use the compressAccurately method to compress the image to certain size. However, when i am trying to compress an image of 3M, i set the config to {size: 100000, accuracy: 99} with same width and height as the original image. The image cannot be compressed to 100kb as wanted. It would end up be compressed image of around 300kb. Hence, would like to know what would be the reason of this. Thanks!

WangYuLue commented 2 years ago

The default unit of size is kb

enjoykcc456 commented 2 years ago

Thanks for the reply. I think there is a typo in my previous comment. I meant to say i set the config to {size: 100, accuracy: 99} to compress the image accurately to 100kb. However, when i try to compress the image with size of around 2 to 3MB, the resulting image wont be accurately 100kb, but around 300kb.

munkk commented 2 years ago

Same here

munkk commented 2 years ago

you have to reduce image dimensions to make it work ex. compressAccurately(file, {size: 100, width:800, height: 600})

zhaoyuanmeng commented 6 months ago

如果不想改变原始的长度和宽度怎么做