View difference between Paste ID: Dfb8TR4g and DcsD0qDQ
SHOW: | | - or go back to the newest paste.
1-
1+
/**
2-
 function toBase64(url) {
2+
 * Converts an image to a base64 string
3
 * Param[in] : url, the path to the image
4-
    var ctx = canvas.getContext('2d'); 
4+
 */
5-
    var img = new Image();
5+
function toBase64(url) {
6-
    img.src = url; 
6+
7-
    var height = img.height, width = img.width;
7+
	var ctx = canvas.getContext('2d'); 
8
    	var img = new Image();
9
    	img.src = url; 
10
    	var height = img.height, width = img.width;
11
	canvas.height = height; 
12-
		var dataURL = canvas.toDataURL("image/jpg"); 
12+
13-
		// To prevent ImageMagick from breaking: ONLY SEND BASE64 ENCRYPTED STRING
13+
14
	try {
15
		var dataURL = canvas.toDataURL("image/jpg");
16
		return dataURL.replace(/^data:image\/(png|jpg);base64,/, "");    
17
	}
18
	catch (err) { console.log("ERROR " + err);}  
19
 }