Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the default quality for HTML5 Canvas.toDataURL?

According to mozilla, the second parameter for canvas.toDataURL(1,2) is:

If the requested type is image/jpeg or image/webp, then the second argument, if it is between 0.0 and 1.0, is treated as indicating image quality; if the second argument is anything else, the default value for image quality is used. Other arguments are ignored.

But I can't find anywhere that tells me what the default value actually is.

like image 722
William T. Avatar asked Apr 02 '13 00:04

William T.


People also ask

What is canvas toDataURL ()?

toDataURL() method returns a data URL containing a representation of the image in the format specified by the type parameter. The desired file format and image quality may be specified. If the file format is not specified, or if the given format is not supported, then the data will be exported as image/png .

Is canvas toDataURL async?

toDataURL is a synchronous operation that does not trigger any events. Being synchronous, it's a blocking operation so no alert is required to prevent the next command from executing before toDataURL is fully complete. The next command will execute when toDataURL is fully complete.

How do you save an html5 canvas as an image on a server?

Saving HTML canvas as an image is pretty easy, it can be done by just right-clicking on the canvas and save it as an image.

How do I find the URL of a canvas image?

To get the image data URL of the canvas, we can use the toDataURL() method of the canvas object which converts the canvas drawing into a 64 bit encoded PNG URL. If you'd like for the image data URL to be in the jpeg format, you can pass image/jpeg as the first argument in the toDataURL() method.


1 Answers

According to the spec, it alludes to the default being browser dependant:

The second argument, if it is a number in the range 0.0 to 1.0 inclusive, must be treated as the desired quality level. If it is not a number or is outside that range, the user agent must use its default value, as if the argument had been omitted.

Edit: According to one user the default for Firefox is 0.92.

You can specify the JPEG quality as the second parameter to the toDataURL function. The default quality in Firefox is 0.92 (92%).

And according to this webkit bug report Chrome uses the same.

...Adds a libjpeg-based image encoder for Skia bitmaps. Default encoding quality is 92 to match Mozilla...

like image 105
Jarrod Avatar answered Sep 19 '22 08:09

Jarrod