Skip to content

Instantly share code, notes, and snippets.

@tmcw
Created March 13, 2013 16:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tmcw/5153896 to your computer and use it in GitHub Desktop.
Save tmcw/5153896 to your computer and use it in GitHub Desktop.

Make a loading gif with gifsicle, node-canvas, and graphicsmagick.

TOGIF = gm mogrify -format gif
all: anim.gif
*.pre.png: loading.js
node loading.js
*.pre.gif: *.pre.png
$(TOGIF) *.pre.png
anim.gif: *.pre.gif
gifsicle -d10 --loop *.pre.gif > anim.gif
{
"name": "img",
"version": "0.0.0",
"description": "ERROR: No README.md file found!",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": "",
"author": "",
"license": "BSD",
"dependencies": {
"canvas": "~1.0.1",
"pad": "0.0.4"
}
}
var Canvas = require('canvas'),
pad = require('pad'),
fs = require('fs');
var w = 10, h = 10;
var c = new Canvas(w, h);
var ctx = c.getContext('2d');
ctx.strokeStyle = '#C5CBCE';
ctx.lineWidth = 2;
for (var i = 0; i < 10; i++) {
ctx.fillStyle = '#E2E2E2';
ctx.fillRect(0, 0, 10, 10);
ctx.beginPath();
ctx.moveTo(i - 10, 0);
ctx.lineTo(i, 10);
ctx.stroke();
ctx.beginPath();
ctx.moveTo(i, 0);
ctx.lineTo(i + 10, 10);
ctx.stroke();
fs.writeFileSync(pad(3, i, '0') + '.pre.png', c.toBuffer());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment