Skip to content

Commit

Permalink
show gif file size #117
Browse files Browse the repository at this point in the history
  • Loading branch information
forresto committed May 13, 2013
1 parent 0589e69 commit 926681d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
5 changes: 4 additions & 1 deletion libs/omggif/omggif-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ self.onmessage = function(event) {
addFrame( frames[i] );
self.postMessage({
type: "progress",
data: Math.round( (i+1)/framesLength*100 )
data: (i+1)/framesLength
});
}

Expand All @@ -106,4 +106,7 @@ self.onmessage = function(event) {
frameCount: framesLength,
encodeTime: Math.round( (Date.now()-startTime)/10 ) / 100
});

// Terminate self
self.close();
};
12 changes: 10 additions & 2 deletions src/nodes/variable-animation.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,15 +245,22 @@ $(function(){
var self = this;
gifWorker.addEventListener('message', function (e) {
if (e.data.type === "progress") {
self.$(".status").text("GIF " + e.data.data + "% encoded...");
self.$(".status").text("GIF " + Math.round(e.data.data*100) + "% encoded...");
} else if (e.data.type === "gif") {
var gifurl = "data:image/gif;base64,"+window.btoa(e.data.data);
var img = $('<img class="image" />')
.attr({
src: gifurl,
style: "max-width:100%"
});
self.$(".exports").prepend( "<div>" + e.data.frameCount + " frames encoded in " + e.data.encodeTime + " seconds</div>" );
// Format file size
var fileSize = Math.round(e.data.data.length / 1024);
var fileSizeUnit = "kb";
if (fileSize >= 1024) {
fileSize = Math.round(fileSize / 1024 * 10) / 10;
var fileSizeUnit = "mb";
}
self.$(".exports").prepend( "<div>" + e.data.frameCount + " frames ("+fileSize+fileSizeUnit+") encoded in " + e.data.encodeTime + "s</div>" );
self.$(".exports").prepend( img );
self.$(".status").text("");

Expand All @@ -263,6 +270,7 @@ $(function(){
}, false);
gifWorker.addEventListener('error', function (e) {
self.$(".status").text("GIF encoding error :-(");
gifWorker.terminate();
}, false);

// Send image data
Expand Down

0 comments on commit 926681d

Please sign in to comment.