Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Google Images draw images using canvas?

Tags:

html

canvas

Updated: Google Images does not use <canvas> any more.


I noticed Google Images is using canvas to render images. <img> is used as a fallback for browsers that does not support canvas.

<a class="rg_l" style="..." href="...">
  <canvas
    id="cvs_NcG8skPEDu7FWM:b"
    style="display:block"
    width="83"
    height="113">
  </canvas>
  <img 
    class="rg_i"
    id="NcG8skPEDu7FWM:b"
    data-src="http://t0.gstatic.com/images?q=tbn:ANd9GcQCB5NEbEUQhtmFI098HLSkfmoHTBtUfERUNkNKrhgFbtFBxZXY9ejXn_pUGg"
    height="113"
    width="83"
    style="width:83px;height:113px"
    onload="google.isr.fillCanvas(this);google.stb.csi.onTbn(0, this)"
    src="http://t0.gstatic.com/images?q=tbn:ANd9GcQCB5NEbEUQhtmFI098HLSkfmoHTBtUfERUNkNKrhgFbtFBxZXY9ejXn_pUGg">
</a>

What's the point of using <canvas> rather than <img>?

like image 720
NVI Avatar asked Dec 17 '10 17:12

NVI


People also ask

What is image canvas?

The Canvas Size command allows you to add space around an image, or to effectively crop an image. So, for example, let's assume you want to print a photo at 11-inches by 17-inches, but on a 13-inch by 19-inch sheet of paper. This doesn't actually require you to add canvas around the photo.

What is the use of canvas in drawing?

A drawing canvas is an object, a bounding box to contain graphics. Use it to provide a background or shading behind AutoShapes and images, group graphics, or to create a wider area for a text wrap. Because the drawing canvas is mostly obsolete, you have to turn it on in Word's options.

Which is the method used to draw image on a canvas?

The drawImage() method draws an image, canvas, or video onto the canvas.

Can you draw on an image in canvas?

The function we use for drawing an image onto a canvas is the drawImage() function. This function draws an image, canvas, or video onto the canvas. It can also draw parts of an image, and/or increase/reduce the image size.


3 Answers

Maybe it gives them more control over the contents of an image.

You can analyze color range of an image, prevailing color, even its content (given smart algorithm).

You can also perform per-pixel modifications — change brightness, contrast, gamma, etc. (not sure why they would want to do this; perhaps for some future use).

You can also rotate an image (on browsers that support canvas but not CSS transformations; see, for example, this demo of my fabric.js).

like image 130
kangax Avatar answered Sep 19 '22 09:09

kangax


Several mobile devices have a limit on the number of image resources on one page. For example, Mobile Safari stops loading images after ± 6.5 MB of images have been loaded.

As mentioned in another answer, by using <canvas> instead of several <img> elements with external files as their src, Google can load all the images in one request (which is obviously better for performance) — but it also works around this limitation.

like image 20
Mathias Bynens Avatar answered Sep 19 '22 09:09

Mathias Bynens


  • You can easily load all the images in one request or even embed their source in the page without inflating the source with base64.
  • You can make copies of images in JS without waiting for the cache.
like image 42
thejh Avatar answered Sep 20 '22 09:09

thejh