Creo Get image data in JavaScript? responde a su pregunta:
// Code taken from MatthewCrumley (https://stackoverflow.com/a/934925/298479)
function getBase64Image(img) {
// Create an empty canvas element
var canvas = document.createElement("canvas");
canvas.width = img.width;
canvas.height = img.height;
// Copy the image contents to the canvas
var ctx = canvas.getContext("2d");
ctx.drawImage(img, 0, 0);
// Get the data-URL formatted image
// Firefox supports PNG and JPEG. You could check img.src to guess the
// original format, but be aware the using "image/jpg" will re-encode the image.
var dataURL = canvas.toDataURL("image/png");
return dataURL.replace(/^data:image\/(png|jpg);base64,/, "");
}
paso dicho img
a esta función. Devolverá la imagen en codificación base64. Sin embargo, será recodificado. Entonces no puedes acceder a los datos de imagen originales.
Pásame, pero así es como lo hice. +1 – Hacknightly
He convertido esto en un bookmarklet aquí: http://jsfiddle.net/bgmort/m26yr/ Abre la imagen que desea en su propia pestaña, luego ejecútela e inserta un área de texto en la pantalla con los datos url. – undefined
En lugar de "dataURL.replace" puede hacer "dataURL.split (',') [1]" que también funcionará para otros formatos que no sean "png" o "jpg". :) –