From 7684ee064c717722003e920baed08d0230eb0d9e Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Mon, 5 Sep 2016 17:27:11 +0100 Subject: Fix photo preview display after submission. If the form is submitted and reshown, due to an error or logging in, the image preview is loaded from the server, rather than the client. We need to get the image source data to get the Exif data out of it. --- web/js/src/exif.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'web/js/src') diff --git a/web/js/src/exif.js b/web/js/src/exif.js index 3a2c7e1c3..f27be8ecb 100644 --- a/web/js/src/exif.js +++ b/web/js/src/exif.js @@ -55,7 +55,19 @@ return false; } - var base64 = img.src.replace(/^data\:([^\;]+)\;base64,/gmi, ''); + var data = img.src; + if (data.match(/^http/)) { + // We're loading this image from the server, presumably after a + // submission, so we have its URL, not yet its data. + var canvas = document.createElement("canvas"), + ctx = canvas.getContext("2d"); + canvas.width = img.width; + canvas.height = img.height; + ctx.drawImage(img, 0, 0); + data = canvas.toDataURL("image/jpeg"); + } + + var base64 = data.replace(/^data\:([^\;]+)\;base64,/gmi, ''); var binary = atob(base64); var len = binary.length; var file = new ArrayBuffer(len); -- cgit v1.2.3