aboutsummaryrefslogtreecommitdiffstats
path: root/web/js/src
diff options
context:
space:
mode:
authorMatthew Somerville <matthew-github@dracos.co.uk>2016-09-05 17:27:11 +0100
committerMatthew Somerville <matthew-github@dracos.co.uk>2016-09-05 17:27:11 +0100
commit7684ee064c717722003e920baed08d0230eb0d9e (patch)
treef79e03118490f1fde8c3f4d91c3a06299d029891 /web/js/src
parent0e45fa27e4bc857f61b71f6c121a61e08e54cb6a (diff)
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.
Diffstat (limited to 'web/js/src')
-rw-r--r--web/js/src/exif.js14
1 files changed, 13 insertions, 1 deletions
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);