Skip to content

Commit b799322

Browse files
Donovan Gloverdomenic
Donovan Glover
authored andcommitted
Give toDataURL() and toBlob() default parameter values
Fixes #3430.
1 parent f75a7b2 commit b799322

File tree

1 file changed

+21
-18
lines changed

1 file changed

+21
-18
lines changed

source

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -59562,8 +59562,8 @@ interface <dfn>HTMLCanvasElement</dfn> : <span>HTMLElement</span> {
5956259562

5956359563
<span>RenderingContext</span>? <span data-x="dom-canvas-getContext">getContext</span>(DOMString contextId, optional any options = null);
5956459564

59565-
USVString <span data-x="dom-canvas-toDataURL">toDataURL</span>(optional DOMString type, optional any quality);
59566-
void <span data-x="dom-canvas-toBlob">toBlob</span>(<span>BlobCallback</span> _callback, optional DOMString type, optional any quality);
59565+
USVString <span data-x="dom-canvas-toDataURL">toDataURL</span>(optional DOMString type = "image/png", optional any quality);
59566+
void <span data-x="dom-canvas-toBlob">toBlob</span>(<span>BlobCallback</span> _callback, optional DOMString type = "image/png", optional any quality);
5956759567
<span>OffscreenCanvas</span> <span data-x="dom-canvas-transferControlToOffscreen">transferControlToOffscreen</span>();
5956859568
};
5956959569

@@ -59961,7 +59961,7 @@ callback <dfn>BlobCallback</dfn> = void (<span>Blob</span>? blob);</code></pre>
5996159961

5996259962
<li><p>Let <var>file</var> be <span data-x="a serialization of the bitmap as a file">a
5996359963
serialization of this <code>canvas</code> element's bitmap as a file</span>, passing
59964-
<var>type</var> and <var>quality</var> if they were given.</p></li>
59964+
<var>type</var> and <var>quality</var> if given.</p></li>
5996559965

5996659966
<li><p>If <var>file</var> is null then return "<code data-x="">data:,</code>".</p></li>
5996759967

@@ -59992,8 +59992,8 @@ callback <dfn>BlobCallback</dfn> = void (<span>Blob</span>? blob);</code></pre>
5999259992

5999359993
<ol>
5999459994
<li><p>If <var>result</var> is non-null, then set <var>result</var> to <span data-x="a
59995-
serialization of the bitmap as a file">a serialization of <var>result</var> as a file</span>,
59996-
with <var>type</var> and <var>quality</var> if they were given.</p></li>
59995+
serialization of the bitmap as a file">a serialization of <var>result</var> as a file</span>
59996+
with <var>type</var> and <var>quality</var> if given.</p></li>
5999759997

5999859998
<li>
5999959999
<p><span>Queue a task</span> to run these steps:</p>
@@ -65294,7 +65294,7 @@ dictionary <dfn>ImageBitmapRenderingContextSettings</dfn> {
6529465294

6529565295
dictionary <dfn>ImageEncodeOptions</dfn> {
6529665296
DOMString <span data-x="image-encode-options-type">type</span> = "image/png";
65297-
unrestricted double <span data-x="image-encode-options-quality">quality</span> = 1.0;
65297+
unrestricted double <span data-x="image-encode-options-quality">quality</span>;
6529865298
};
6529965299

6530065300
enum <dfn>OffscreenRenderingContextId</dfn> { "<span data-x="offscreen-context-type-2d">2d</span>", "<span data-x="offscreen-context-type-webgl">webgl</span>", "<span data-x="offscreen-context-type-webgl2">webgl2</span>" };
@@ -65612,7 +65612,7 @@ interface <dfn>OffscreenCanvas</dfn> : <span>EventTarget</span> {
6561265612
<li><p>Let <var>file</var> be <span data-x="a serialization of the bitmap as a file">a
6561365613
serialization of <var>bitmap</var> as a file</span>, with <var>options</var>'s <dfn><code
6561465614
data-x="image-encode-options-type">type</code></dfn> and <dfn><code
65615-
data-x="image-encode-options-quality">quality</code></dfn>.</p></li>
65615+
data-x="image-encode-options-quality">quality</code></dfn> if present.</p></li>
6561665616

6561765617
<li>
6561865618
<p><span>Queue a task</span> to run these steps:</p>
@@ -65892,11 +65892,10 @@ interface <dfn>OffscreenCanvasRenderingContext2D</dfn> {
6589265892
<div w-nodev>
6589365893

6589465894
<p>When a user agent is to create <!--en-GB--><dfn id="a-serialisation-of-the-bitmap-as-a-file">a
65895-
serialization of the bitmap as a file</dfn>, given an optional <var>type</var> and
65896-
<var>quality</var>, it must create an image file in the format given by <var>type</var>, or if
65897-
<var>type</var> was not supplied, in the PNG format. If an error occurs during the creation of
65898-
the image file (e.g. an internal encoder error), then the result of the serialization is null.
65899-
<ref spec=PNG></p>
65895+
serialization of the bitmap as a file</dfn>, given a <var>type</var> and an optional
65896+
<var>quality</var>, it must create an image file in the format given by <var>type</var>. If an
65897+
error occurs during the creation of the image file (e.g. an internal encoder error), then the
65898+
result of the serialization is null. <ref spec=PNG></p>
6590065899

6590165900
<p>The image file's pixel data must be the bitmap's pixel data scaled to one image pixel per
6590265901
coordinate space unit, and if the file format used supports encoding resolution metadata, the
@@ -65923,16 +65922,20 @@ interface <dfn>OffscreenCanvasRenderingContext2D</dfn> {
6592365922
image composited onto an <span>opaque black</span> background using the source-over operator.</p>
6592465923

6592565924
<p>If <var>type</var> is an image format that supports variable quality (such as
65926-
"<code>image/jpeg</code>") and <var>quality</var> is given, then, if <span
65927-
data-x="js-Type">Type</span>(<var>quality</var>) is Number, and <var>quality</var> is in the range
65928-
0.0 to 1.0 inclusive, the user agent must treat <var>quality</var> as the desired quality level.
65929-
If <span data-x="js-Type">Type</span>(<var>quality</var>) is not Number, or if <var>quality</var>
65930-
is outside that range, the user agent must use its default quality value, as if the
65931-
<var>quality</var> argument had not been given.</p>
65925+
"<code>image/jpeg</code>"), <var>quality</var> is given, and <var>type</var> is not
65926+
"<code>image/png</code>", then, if <span data-x="js-Type">Type</span>(<var>quality</var>) is
65927+
Number, and <var>quality</var> is in the range 0.0 to 1.0 inclusive, the user agent must treat
65928+
<var>quality</var> as the desired quality level. Otherwise, the user agent must use its default
65929+
quality value, as if the <var>quality</var> argument had not been given.</p>
6593265930

6593365931
<p class="note">The use of type-testing here, instead of simply declaring <var>quality</var> as
6593465932
a Web IDL <code data-x="">double</code>, is a historical artifact.</p>
6593565933

65934+
<p class="note">Different implementations can have slightly different interpretations of
65935+
"quality". When the quality is not specified, an implementation-specific default is used that
65936+
represents a reasonable compromise between compression ratio, image quality, and encoding
65937+
time.</p>
65938+
6593665939
</div>
6593765940

6593865941

0 commit comments

Comments
 (0)