// variables related to canvas
var canvas=document.getElementById("canvas");
var ctx=canvas.getContext("2d");
var cw,ch;
// loading the logo and its outline
// then initiating the animation
var logoOutline;
var logo=new Image();
logo.onload=start;
logo.src='https://dl.dropboxusercontent.com/u/139992952/multple/marioStanding.png';
function start(){
logoOutline=outlinePNG(logo,'lightgray');
cw=canvas.width=logoOutline.width;
ch=canvas.height=logoOutline.height;
canvas.style.border='1px solid red';
logo.displayY=logo.height-2;
requestAnimationFrame(animate);
}
function animate(time){
// storing logo.displayY in a variable since it's used frequently
var y=logo.displayY;
// clearing the logo canvas
ctx.clearRect(0,0,cw,ch);
// using the clipping version of drawImage to
// gradually reveal the logo from the bottom
ctx.drawImage(logo,
0,y,logo.width,logo.height-y,
2,y+2,logo.width,logo.height-y);
// decreasing .displayY to increase the reveal
logo.displayY--;
// requesting another loop if the entire logo has not been revealed
if(logo.displayY>0){
// drawing the outline
ctx.drawImage(logoOutline,0,0);
// requesting another loop until the full logo is displayed
requestAnimationFrame(animate);
}
}
//
// Credit: Ken Fyrstenberg
// http://stackoverflow.com/questions/25467349/in-a-2d-canvas-is-there-a-way-to-give-a-sprite-an-outline/27127273#27127273
function outlinePNG(img,outlineColor){
// creating a new canvas with image size + 2px on each side
var c=document.createElement('canvas');
var cctx=c.getContext('2d');
c.width=img.width+4;
c.height=img.height+4;
// redrawing the image with 8-way offsets (n,s,e,w,nw,ne,se,sw)
cctx.translate(2,2);
cctx.drawImage(img, -2, -2);
cctx.drawImage(img, 0, -2);
cctx.drawImage(img, 2, -2);
cctx.drawImage(img, -2, 0);
cctx.drawImage(img, 2, 0);
cctx.drawImage(img, -2, 2);
cctx.drawImage(img, 0, 2);
cctx.drawImage(img, 2, 2);
cctx.translate(-2,-2);
// fill with color
cctx.globalCompositeOperation="source-in";
cctx.fillStyle=outlineColor;
cctx.fillRect(0,0,img.width+4,img.height+4);
// draw original image in "erase" mode
cctx.globalCompositeOperation = "destination-out";
cctx.drawImage(img,2,2);
// returning the outline canvas
return(c);
}
<canvas id="canvas" width=300 height=300></canvas>