Re: [whatwg] Canvas image to blob/dataurl within Worker

On Sat, Mar 21, 2015 at 1:13 AM, Jake Archibald <jaffathecake@gmail.com>
wrote:

> Receiving a push message results in a 'push' event within the
> ServiceWorker. The likely action at this point is to show a notification.
> It should be possible to generate an image to use as an icon for this
> notification (
> https://notifications.spec.whatwg.org/#dom-notificationoptions-icon).
>
> This could be a badge showing some kind of unread count, some combination
> of app icon & avatar, or even a default avatar (Google Inbox generates an
> avatar from the senders names first letter).
>
> This is also useful for generating images to go into the cache API, or
> transforming images as they pass through the ServiceWorker.
>
> API:
>
> Almost all the pieces already exist, except a way to get the image data of
> a CanvasRenderingContext2D into a format that can be read from a
> url. ImageBitmap seems like a good fit for such an API:
>
> var context = new CanvasRenderingContext2D(192, 192);
>
> Promise.all(
>   caches.match('/avatars/ben.png')
>     .then(r => r.blob())
>     .then(b => createImageBitmap(b)),
>   caches.match('/avatars/julie.png')
>     .then(r => r.blob())
>     .then(b => createImageBitmap(b)),
> ).then(([ben, julie]) => {
>   context.drawImage(ben, 0, 0);
>   context.drawImage(julie, 96, 96);
>   return createImageBitmap(context);
> }).then(
>   // **** and here's the bit we're missing… ****
>   image => image.toDataURL()
> ).then(icon => {
>   self.registration.showNotificaiton("Hello!", {icon});
> });
>

My understanding is that the current consensus proposal for canvas in
Workers is not what's in the spec, but this:
https://wiki.whatwg.org/wiki/WorkerCanvas
See "Canvas in Workers" threads from October 2013 for the discussion. svn
is failing me but the CanvasProxy proposal in the spec definitely predates
those threads.

Ian, unless I'm wrong, it would be helpful to remove the CanvasProxy stuff
from the spec to avoid confusion.

That proposal contains WorkerCanvas.toBlob, which needs to be updated to
use promises.

Rob
-- 
oIo otoeololo oyooouo otohoaoto oaonoyooonoeo owohooo oioso oaonogoroyo
owoiotoho oao oboroootohoeoro oooro osoiosotoeoro owoiololo oboeo
osouobojoeocoto otooo ojouodogomoeonoto.o oAogoaoiono,o oaonoyooonoeo
owohooo
osoaoyoso otooo oao oboroootohoeoro oooro osoiosotoeoro,o o‘oRoaocoao,o’o
oioso
oaonosowoeoroaoboloeo otooo otohoeo ocooouoroto.o oAonodo oaonoyooonoeo
owohooo
osoaoyoso,o o‘oYooouo ofooooolo!o’o owoiololo oboeo oiono odoaonogoeoro
ooofo
otohoeo ofoioroeo ooofo ohoeololo.

Received on Friday, 20 March 2015 22:16:07 UTC