Termini di utilizzo

Copyright © 2013 Erika Cei. Tutti i diritti riservati. Immagini e testi non possono essere scaricati, manipolati né riprodotti in nessuna circostanza.

mercoledì 16 luglio 2014

Prova per related posts

questa è una prova di primo post con una nuova etichetta

Nessun commento:

Posta un commento

Nota. Solo i membri di questo blog possono postare un commento.

/** * Converts image URLs to dataURL schema using Javascript only. * * @param {String} url Location of the image file * @param {Function} success Callback function that will handle successful responses. This function should take one parameter * dataURL which will be a type of String. * @param {Function} error Error handler. * * @example * var onSuccess = function(e){ * document.body.appendChild(e.image); * alert(e.data); * }; * * var onError = function(e){ * alert(e.message); * }; * * getImageDataURL('myimage.png', onSuccess, onError); * */ function getImageDataURL(url, success, error) { var data, canvas, ctx; var img = new Image(); img.onload = function(){ // Create the canvas element. canvas = document.createElement('canvas'); canvas.width = img.width; canvas.height = img.height; // Get '2d' context and draw the image. ctx = canvas.getContext("2d"); ctx.drawImage(img, 0, 0); // Get canvas data URL try{ data = canvas.toDataURL(); success({image:img, data:data}); }catch(e){ error(e); } } // Load image URL. try{ img.src = url; }catch(e){ error(e); } }