Created
June 27, 2014 16:13
-
-
Save zaftzaft/f337b41f4c836b8a2a87 to your computer and use it in GitHub Desktop.
PixivのUgoiraをGIFにするブックマークレット的なやつ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// あとでリファクタリングする | |
var b = "https://raw.githubusercontent.com/antimatter15/jsgif/master/"; | |
var u = [ | |
"LZWEncoder.js", "NeuQuant.js", "GIFEncoder.js", "Demos/b64.js" | |
]; | |
$("canvas").remove(); | |
var $c = $("<canvas>").appendTo("body"); | |
var ctx = $c[0].getContext("2d"); | |
var d = document; | |
var i = 0; | |
u.forEach(function(r){ | |
var s = d.createElement("script"); | |
s.src = b + r; | |
s.onload = function(){ | |
if(++i == u.length){ | |
load(); | |
} | |
}; | |
d.body.appendChild(s); | |
}); | |
function load(){ | |
var e = new GIFEncoder(); | |
e.setRepeat(0); | |
e.setDelay(20); | |
e.start(); | |
var d = pixiv.context.ugokuIllustData; | |
var w = d.size[0] / 2; | |
var h = d.size[1] / 2; | |
$c.attr({ | |
width: w, | |
height: h | |
}); | |
var z = new ZipImagePlayer({ | |
canvas: $c[0], | |
source: d.src, | |
metadata: d, | |
chunkSize: 3e5, | |
loop: 1, | |
autoStart: false | |
}); | |
$(z).on("loadingStateChanged", function(a, c){ | |
if(c === 2){ | |
var imgs = z._frameImages; | |
(function f(i){ | |
if(i == imgs.length){ | |
var bin = e.stream().getData(); | |
var url = 'data:image/gif;base64,'+encode64(bin); | |
console.log(url); | |
return; | |
} | |
var img = imgs[i]; | |
ctx.drawImage(img, 0, 0, w, h); | |
e.addFrame(ctx); | |
return f(++i); | |
})(0); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment