It's more resize than compress. If you wanted compression, try something like squoosh.app - transpiling image codecs and running them in the front end.
Actually, it is a percentage of signal quality for the quantizer to aim for. While the result is compression, what you set there is the amount of signal loss you deem acceptable.
I can not confirm your words, but I trust the documentation
A Number between 0 and 1 indicating the image quality to use for image formats that use lossy compression such as image/jpeg and image/webp. If this argument is anything else, the default value for image quality is used. The default value is 0.92. Other arguments are ignored.
I wonder if this would be the perfect thing to delegate to WebAssembly, what do you think? It might become slow with big images (also it's going to happen in the calling thread, right?)
Just a note, the
width > heightcheck only works correctly whenmaxHeight === maxWidth:It's more resize than compress. If you wanted compression, try something like squoosh.app - transpiling image codecs and running them in the front end.
Why only resize? This is resize and compression, though not some advanced as squoosh. But the goals of the application is enough
canvas.toDataURL('image/jpeg', 0.7)0.7 - is compression rankdeveloper.mozilla.org/en-US/docs/W...
Actually, it is a percentage of signal quality for the quantizer to aim for. While the result is compression, what you set there is the amount of signal loss you deem acceptable.
I can not confirm your words, but I trust the documentation
That is exactly what I was referring to: you set the quality of the image in a lossy codec, not the compression factor (though both might coincide).
Got it )
I wonder if this would be the perfect thing to delegate to WebAssembly, what do you think? It might become slow with big images (also it's going to happen in the calling thread, right?)
Sadly, but i'am dummy in WebAssembly 😬 So I can't say anything about that.
Well, it's not like I'm an expert either. But we can learn things 😉
In the meantime you can test what happens to the function if you give it a truly massive image
Definitely