0

I have a script that shows random images on a page which I'd like to take log of via Javascript or PHP. The problem is, image source is something like /random.php. How can I retrieve image data without losing the actual random assigned to that page?

Thanks,

2 Answers2

2

Does this javascript do the trick:

function getBase64Image(img) {
    var canvas = document.createElement("canvas");
    canvas.width = img.width;
    canvas.height = img.height;
    var ctx = canvas.getContext("2d");
    ctx.drawImage(img, 0, 0);
    var dataURL = canvas.toDataURL("image/png");
    return dataURL.replace(/^data:image\/(png|jpg);base64,/, "");
}

Usage with jQuery selector:

getBase64Image($('#omg')[0])

where omg is the id of your image

0

Usahe with this link

http://lorempixel.com/300/300/

It use random image and custom size

Just Like this.

<img src="http://lorempixel.com/300/300/">
LV100
  • 1
  • 3