-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
canvas.toDataURL() method will make image larger in size #4906
Comments
https://fabricjs.com/docs/fabric.Canvas.html#toDataURL Try setting format to jpeg and adjusting the quality value. |
It depends how big is the image you download. |
@asturur :The original image resolution is 3914*2935 and it is jpg image.The size of original image is 2.3MB only. Thanks! |
@fte10kso : If I use quality parameter then it will distort the downloaded image? I have a doubt regarding the quality that's why. |
I'm not an expert on image compression but... Since jpeg is lossy you will always lose some information even when quality is 1. This is more noticeable for things like text. As you've already noticed changing format from png (lossless) already reduced your file size by 5MB. What level of compressions is acceptable will depend on the image and what you want to use it for. If I'm not mistaken fabric just uses the corresponding canvas method when saving (https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toDataURL). You could try creating a regular canvas with just the image to see if you get a different result. Most likely the original image already has additional compression. e.g using ImageMagick convert and this image
|
So the point is that your original jpeg is probably looking good, but with some compression artifact you can see if you zoom. When applying this on the canvas and saving with jpeg 100% quality the canvas will apply jpeg compression on what is now a pure bitmap with no image format. Your picture has added crispness or details that are the compression artifact or loss from the previous jpeg. This make the job for the jpeg algorithm harder since it has to save more stuff. A quality parity the size increase probably each jpeg saving, while at size parity the quality decrease. You have to use quality parameter on jpeg, and yes you will loose a bit of quality since canvas JPEG compression is not the best in class |
I'm using fabric.js for image modification(Put text only image0.
After modification done when i download image using toDataURL() method it will result very large image in size.
For example my source image is 2MB only but when i download it after putting some text on the canvas it will increse downloed image size to 13MB which is surprised to me.
Any help in this appreciated.
Thanks.
The text was updated successfully, but these errors were encountered: