W3C home > Mailing lists > Public > public-media-capture@w3.org > March 2012

PROPOSAL: Simple image capture API

From: Anant Narayanan <anant@mozilla.com>
Date: Tue, 6 Mar 2012 11:19:38 -0800
Message-Id: <5029042F-FD24-4FBE-9CC6-9BEACA283107@mozilla.com>
To: public-media-capture@w3.org
We propose a simple addition to getUserMedia to support the simplest use-case of capturing an image from JavaScript, like so:
	navigator.getUserMedia({'picture': true}, function(Blob blob) {  });

There already exists a simple declarative API based on <input> tag specified by the DAP working group (at http://www.w3.org/TR/2011/WD-html-media-capture-20110414/). It works by adding markup like:

	<input type="file" accept="image/*" id="capture">

which, on user action, results in the ability to either select an image from local disk or the webcam.  We have found the need to expose the same functionality, but as an API (programmatic approach vs. the declarative one that has already been specified). Rather than coming up with a new API, we propose that we extend getUserMedia to capture this use-case as well.

The proposed API also fulfills use case 2.1 "check out my new hat", as specified in the scenarios document (http://dvcs.w3.org/hg/dap/raw-file/tip/media-stream-capture/scenarios.html).

Invoking navigator.getUserMedia({'picture': true}); will *not* result in a permission prompt (unlike when either 'audio' or 'video' are set to true). Instead, browser chrome will be presented to the user that allows them to preview local devices and snap a picture (or select a local image file). User action on the preview window is implied consent.

It is already possible to take a picture with getUserMedia({'video':true}), for example: https://gist.github.com/1852070 (real working code that runs on the Opera Labs version). However, we would like to avoid a dependency on MediaStreams as well as permission prompts for this simple use case and first implementation at Mozilla. I think this is a great starting point.

The key difference from the existing getUserMedia spec is that the success callback contains a Blob object if 'picture' was set to true. Blob is fully specified in http://www.w3.org/TR/FileAPI/.

This current proposal uses a callback approach but can be updated as necessary when we have consensus on events (a proposal which I will send out separately).

I look forward to your feedback!

Received on Tuesday, 6 March 2012 19:20:16 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 16:26:09 UTC