summaryrefslogtreecommitdiff
path: root/js/util.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/util.js')
-rw-r--r--js/util.js38
1 files changed, 38 insertions, 0 deletions
diff --git a/js/util.js b/js/util.js
index 9dc306c..fc27166 100644
--- a/js/util.js
+++ b/js/util.js
@@ -1,3 +1,41 @@
$.fn.int = function(){ return parseInt($(this).val(),10) }
$.fn.float = function(){ return parseFloat($(this).val()) }
function clamp(n,a,b){ return n<a?a:n<b?n:b }
+
+function loadImage(imageURL, callback) {
+ document.getElementById("save").style.display = "none"
+ document.getElementById("encode").style.display = "none"
+ status("loading")
+ var imageURL = proxify( imageURL );
+
+ window.gif = window.img = null
+
+ if (imageURL.substr(-3) === "gif") {
+ window.gif = GIF(imageURL);
+ // gif.on("error", tryToLoadNextImage);
+ // gif.on("rendered", trackLoadTime);
+ gif.on("rendered", callback);
+ return gif.render();
+ } else {
+ window.img = new Image();
+ // img.addEventListener("error", tryToLoadNextImage);
+ img.addEventListener("load", callback);
+ img.crossOrigin = "anonymous";
+ return img.src = imageURL;
+ }
+}
+
+function giveImage() {
+ if (imageURL.substr(-3) === "gif") {
+ return gif.frames[gif.currentFrame()].ctx.canvas;
+ } else {
+ return img;
+ }
+}
+
+function proxify (url) {
+ if (url.indexOf("http") == 0)
+ return "/cgi-bin/proxy?" + url // .replace(/^https?:\/\//, "");
+ else
+ return url
+};