[whatwg] Image resize API proposal
Kornel Lesinski
kornel at geekhood.net
Tue May 25 03:58:55 PDT 2010
On 24 May 2010, at 22:09, David Levin wrote:
> > that even if it was implemented everywhere, this solution involves readback
> > from the GPU which, as Chris mentioned, is generally evil and should be
> > avoided at all costs.
>
> This I'm not qualified to comment on, though. To the best of my
> knowledge, GPUs are magical boxes that make things go faster via pixie
> dust. ;)
>
> Thanks for your opinion. :)
>
> Chris is qualified so are other people whom I've spoken to who have said the same thing, so using the gpu is not pixie dust in this particular scenario even though folks would like to be believe it so.
I think GPU readback is a red herring. It's an operation that takes milliseconds. It's "slow" for realtime graphics, but it's not something that user is going to notice when uploading images — users are not uploading hundreds of images per second.
If UA can parallelize decoding, scaling, encoding and sending, the operation can be very fast and memory-efficient, even if scaling is done very slowly (it won't have noticeable impact as long as it's not slower than uploading).
JPEG can be efficiently decoded at fraction of its size — without full decode and scale process. This process also needs only fraction of memory required for full scaling, which might matter on low-end mobile devices. Letting UA utilize this feature may give huge performance gains.
Scaling isn't the only operation desirable — in some cases users might also want to crop the image (e.g., to upload only their face as an avatar), and cropping interface needs to be platform-specific — on touchscreen devices I'd rather use gestures than select-by-click'n'drag interface typical for desktop.
I think scaling of images before upload might be left completely up to UA. From site's perspective it could look like user simply selected scaled-down file. It could even be done declaratively — site could define desired size and whether user should be asked to crop the image:
<input type="file" accept="image/*" max-image-size="1000x1000" crop="allowed">
Actually, I wish UAs offered scaling even for plain <input type=file>, because I don't expect every site with image upload to add extra code for resizing.
--
regards, Kornel
More information about the whatwg
mailing list