<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://www.w3.org/Bugs/Public/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4"
          urlbase="https://www.w3.org/Bugs/Public/"
          
          maintainer="sysbot+bugzilla@w3.org"
>

    <bug>
          <bug_id>15041</bug_id>
          
          <creation_ts>2011-12-02 11:25:10 +0000</creation_ts>
          <short_desc>Clarify dimensions of image returned by Canvas toDataURL</short_desc>
          <delta_ts>2013-03-11 23:49:21 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>HTML WG</product>
          <component>HTML5 spec</component>
          <version>unspecified</version>
          <rep_platform>PC</rep_platform>
          <op_sys>Linux</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="John Knottenbelt">jknotten</reporter>
          <assigned_to name="Silvia Pfeiffer">silviapfeiffer1</assigned_to>
          <cc>cabanier</cc>
    
    <cc>eoconnor</cc>
    
    <cc>erika.doyle</cc>
    
    <cc>ian</cc>
    
    <cc>jackalmage</cc>
    
    <cc>mike</cc>
    
    <cc>plh</cc>
    
    <cc>public-html-admin</cc>
    
    <cc>public-html-wg-issue-tracking</cc>
    
    <cc>silviapfeiffer1</cc>
    
    <cc>smfr</cc>
          
          <qa_contact name="HTML WG Bugzilla archive list">public-html-bugzilla</qa_contact>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>60772</commentid>
    <comment_count>0</comment_count>
    <who name="John Knottenbelt">jknotten</who>
    <bug_when>2011-12-02 11:25:10 +0000</bug_when>
    <thetext>It seems suggested, but not explicitly stated, that the dimensions of the image produced by toDataURL will match that of the underlying image data, as returned by context.getImageData(). The dimensions of the produced image will, therefore, not necessarily be the same as width and height properties of the canvas. 

It would be great to clarify this point in the spec. 

Below are some related paragraphs in the spec:

4.8.11.1

&quot;The toDataURL() method must not include color space information in the resource returned. Where the output format allows it, the color of pixels in resources created by toDataURL() must match those returned by the getImageData() method.&quot;

...

&quot;Thus, in the 2D context, calling the drawImage() method to render the output of the toDataURL() method to the canvas, given the appropriate dimensions, has no visible effect.&quot;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>60777</commentid>
    <comment_count>1</comment_count>
    <who name="Tab Atkins Jr.">jackalmage</who>
    <bug_when>2011-12-02 16:30:18 +0000</bug_when>
    <thetext>I disagree that toDataURL should have the same behavior as getImageData here.

getImageData is sensitive to the backing-store resolution, and importantly, will correctly round-trip an image.

toDataURL should be producing an image identical to what&apos;s displayed in the canvas.  If it produces an image with one image pixel = one backing store pixel, then it won&apos;t roundtrip through canvas, which your spec quote implies should happen.

toDataURL, thus, should use screen pixels, not backing store pixels.

If an output format support sub-pixel information, then sure, include it.  But for formats like JPEG and PNG, it shouldn&apos;t.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>60826</commentid>
    <comment_count>2</comment_count>
    <who name="Simon Fraser">smfr</who>
    <bug_when>2011-12-02 19:15:50 +0000</bug_when>
    <thetext>(In reply to comment #1)

&gt; toDataURL should be producing an image identical to what&apos;s displayed in the
&gt; canvas.  If it produces an image with one image pixel = one backing store
&gt; pixel, then it won&apos;t roundtrip through canvas, which your spec quote implies
&gt; should happen.
&gt; 
&gt; toDataURL, thus, should use screen pixels, not backing store pixels.

These two statements are not logically consistent. If the canvas has 2x backing store, but toDataURL uses screen pixels, then the toDataURL image will look fuzzy compared to the canvas on a 2x display.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>60830</commentid>
    <comment_count>3</comment_count>
    <who name="Tab Atkins Jr.">jackalmage</who>
    <bug_when>2011-12-02 19:22:05 +0000</bug_when>
    <thetext>(In reply to comment #2)
&gt; (In reply to comment #1)
&gt; 
&gt; &gt; toDataURL should be producing an image identical to what&apos;s displayed in the
&gt; &gt; canvas.  If it produces an image with one image pixel = one backing store
&gt; &gt; pixel, then it won&apos;t roundtrip through canvas, which your spec quote implies
&gt; &gt; should happen.
&gt; &gt; 
&gt; &gt; toDataURL, thus, should use screen pixels, not backing store pixels.
&gt; 
&gt; These two statements are not logically consistent. If the canvas has 2x backing
&gt; store, but toDataURL uses screen pixels, then the toDataURL image will look
&gt; fuzzy compared to the canvas on a 2x display.

But an image generated with 1 image pixel = 1 backing-store pixel will look double-size.

So, we&apos;ve gotta make some sacrifices somewhere.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>60831</commentid>
    <comment_count>4</comment_count>
    <who name="Simon Fraser">smfr</who>
    <bug_when>2011-12-02 19:23:20 +0000</bug_when>
    <thetext>(In reply to comment #3)
&gt; But an image generated with 1 image pixel = 1 backing-store pixel will look
&gt; double-size.
&gt; 
&gt; So, we&apos;ve gotta make some sacrifices somewhere.

Right. So do you make things lossy but work for naive web developers, or non-lossy but require a bit more web author smarts? We went the latter route for getImageData().</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>60832</commentid>
    <comment_count>5</comment_count>
    <who name="Tab Atkins Jr.">jackalmage</who>
    <bug_when>2011-12-02 19:27:15 +0000</bug_when>
    <thetext>(In reply to comment #4)
&gt; (In reply to comment #3)
&gt; &gt; But an image generated with 1 image pixel = 1 backing-store pixel will look
&gt; &gt; double-size.
&gt; &gt; 
&gt; &gt; So, we&apos;ve gotta make some sacrifices somewhere.
&gt; 
&gt; Right. So do you make things lossy but work for naive web developers, or
&gt; non-lossy but require a bit more web author smarts? We went the latter route
&gt; for getImageData().

Yes, and I think that was the right choice - when you&apos;re pulling out the image data explicitly, you generally actually want the real data.

However, there&apos;s no way to express the dpi of an image in a way that a web browser will automatically pay attention to, unfortunately.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>67294</commentid>
    <comment_count>6</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2012-05-03 16:48:16 +0000</bug_when>
    <thetext>We&apos;re likely to add an HD version of getImageData() that&apos;s defined as the current one is and redefine the current one to use CSS pixel resolution, so maybe we should do the same with toDataURL and have a toDataURLHD?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>67296</commentid>
    <comment_count>7</comment_count>
    <who name="Edward O&apos;Connor">eoconnor</who>
    <bug_when>2012-05-03 17:08:14 +0000</bug_when>
    <thetext>Sounds reasonable to me.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>70418</commentid>
    <comment_count>8</comment_count>
    <who name="">contributor</who>
    <bug_when>2012-07-18 07:27:38 +0000</bug_when>
    <thetext>This bug was cloned to create bug 17978 as part of operation convergence.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>72073</commentid>
    <comment_count>9</comment_count>
    <who name="Silvia Pfeiffer">silviapfeiffer1</who>
    <bug_when>2012-08-11 05:55:47 +0000</bug_when>
    <thetext>Moved to canvas component.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>72544</commentid>
    <comment_count>10</comment_count>
    <who name="rcabanie">cabanier</who>
    <bug_when>2012-08-22 18:37:07 +0000</bug_when>
    <thetext>This is a new feature. Moving it to  HTML.next

This is also not part of the canvas 2D spec. Moving it to HTML</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>81709</commentid>
    <comment_count>11</comment_count>
    <who name="Robin Berjon">robin</who>
    <bug_when>2013-01-21 15:59:12 +0000</bug_when>
    <thetext>Mass move to &quot;HTML WG&quot;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>81827</commentid>
    <comment_count>12</comment_count>
    <who name="Robin Berjon">robin</who>
    <bug_when>2013-01-21 16:01:58 +0000</bug_when>
    <thetext>Mass move to &quot;HTML WG&quot;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>84273</commentid>
    <comment_count>13</comment_count>
    <who name="Erika Doyle Navara">erika.doyle</who>
    <bug_when>2013-03-11 23:49:21 +0000</bug_when>
    <thetext>EDITOR&apos;S RESPONSE: This is an Editor&apos;s Response to your comment. If you are
satisfied with this response, please change the state of this bug to CLOSED. If
you have additional information and would like the Editor to reconsider, please
reopen this bug. If you would like to escalate the issue to the full HTML
Working Group, please add the TrackerRequest keyword to this bug, and suggest
title and text for the Tracker Issue; or you may create a Tracker Issue
yourself, if you are able to do so. For more details, see this document:


   http://dev.w3.org/html5/decision-policy/decision-policy.html

Status: Accepted
Change Description: None (already in the spec)
Rationale: 
Since the filing of this bug, the W3C spec has incorporated the toDataURL, toDataURLHD, getImageData, and getImageDataHD definitions and clarifying text from the WHATWG spec:

https://github.com/w3c/html/commit/857a787b304e602a1cb2fea21b6dbfcb29107a09</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>