[whatwg] toDataURL() for image/video?
ashley at scirra.com
Tue May 29 11:41:42 PDT 2012
Has toDataURL() (from canvas) been considered for ordinary image and video
Currently it can be done by creating a new canvas, getting a 2D context,
drawImage(), then canvas.toDataURL(). However adding it to images directly
would be a useful convenience method, avoid the performance overhead of a
new canvas, and probably be straightforward to define/implement.
Use cases for myimage.toDataURL():
- deep copy an image (imga.src = imgb.toDataURL())
- send an image in JSON data
- conveniently store in webstorage/other permanent storage (possibly also
for caching purposes?)
- downloading an image to disk (depending on other features like anchor's
it would have to be disallowed for cross-domain images, else canvas' dirty
flag can be worked around by deep copying a cross-domain image.
It seems to make sense to also consider it for video, but it may be
difficult to deal with streaming or strings storing very large amounts of
data. How about a snapshot() method that returns a new Image() with the
contents of the currently displaying frame? This can also be worked around
by drawImage() to a temporary canvas, so exists just as a convenience
method as well.
- easily get a representative frame, e.g. for a thumbnail
- easily snapshot the current frame when displaying webcam feed with
getUserMedia(). e.g. var myPhoto = video.snapshot();, or some of the above
uses with video.snapshot().toDataURL().
More information about the whatwg