W3C home > Mailing lists > Public > whatwg@whatwg.org > March 2015

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

From: Robert O'Callahan <robert@ocallahan.org>
Date: Sat, 21 Mar 2015 11:15:42 +1300
Message-ID: <CAOp6jLbYZYtaPPMxbrU+AiOovdFmi2WQBnYwe=LPkF6PZv7Hfw@mail.gmail.com>
To: Jake Archibald <jaffathecake@gmail.com>, Ian Hickson <ian@hixie.ch>
Cc: WHATWG <whatwg@whatwg.org>
On Sat, Mar 21, 2015 at 1:13 AM, Jake Archibald <jaffathecake@gmail.com>

> 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:
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.

oIo otoeololo oyooouo otohoaoto oaonoyooonoeo owohooo oioso oaonogoroyo
owoiotoho oao oboroootohoeoro oooro osoiosotoeoro owoiololo oboeo
osouobojoeocoto otooo ojouodogomoeonoto.o oAogoaoiono,o oaonoyooonoeo
osoaoyoso otooo oao oboroootohoeoro oooro osoiosotoeoro,o o‘oRoaocoao,o’o
oaonosowoeoroaoboloeo otooo otohoeo ocooouoroto.o oAonodo oaonoyooonoeo
osoaoyoso,o o‘oYooouo ofooooolo!o’o owoiololo oboeo oiono odoaonogoeoro
otohoeo ofoioroeo ooofo ohoeololo.
Received on Friday, 20 March 2015 22:16:07 UTC

This archive was generated by hypermail 2.4.0 : Wednesday, 22 January 2020 17:00:29 UTC