canvas-toBlob.js icon indicating copy to clipboard operation
canvas-toBlob.js copied to clipboard

Don't use mozGetAsFile when quality is passed

Open dantman opened this issue 9 years ago • 4 comments

mozGetAsFile doesn't accept a quality argument like toDataURI as a result the quality argument on toBlob won't have an effect on jpeg and webp images.

dantman avatar Feb 22 '15 19:02 dantman

The performance benefits greatly outweigh the slight performance increase of using quality+toDataURI as the base64 encoding overhead is still much much greater. Unfortunately no matter what (reasonably high enough) quality is selected in toDataURI, it will always be slower than mozGetAsFile. Do you have any significant non-performance reasons to use quality+toDataURI?

eligrey avatar Feb 22 '15 19:02 eligrey

Performance? Stripping the quality gives you the wrong file. The point of quality is to affect the image quality / filesize of the file. If you strip it out then you're not giving the file that toBlob is expected to give out.

Local performance is irrelevant if you upload the wrong quality blob to the server.

It's pretty irrelevant anyways since Firefox has native toBlob now. The only people using mozGetAsFile are using outdated Firefox. Trying to optimize performance for them at the cost of getting the correct output is pointless.

dantman avatar Feb 22 '15 19:02 dantman

The whole point of using toBlob instead of toDataURL is performance, and it's not like I added the moz method to support old Firefoxes--it was added back when it was the only performant method in any Firefox. You are still getting the correct image format, just not at the desired quality.

I understand your concern though and I will accept a patch that uses toDataURL instead of the moz method when the format is image/jpeg and a non-1 quality is specified.

eligrey avatar Feb 22 '15 20:02 eligrey

The whole point of using toBlob instead of toDataURL is performance, and it's not like I added the moz method to support old Firefoxes--it was added back when it was the only performant method in any Firefox. You are still getting the correct image format, just not at the desired quality.

To me the whole point of using toBlob instead of toDataURL is getting a format that XHR2 will accept and upload with xhr.upload.

In any case thanks for responding. I don't need the IE9- base64 support or toBlobHD so I just went with using canvas-to-blob for my project.

dantman avatar Feb 22 '15 20:02 dantman