As others mentioned, the cross domain issue is the problem. Unfortunately, tumblr uses a different domain for images than the one your blog is hosted on. I used a third-party conversion site in the demo below (http://www.maxnov.com/getimagedata) to get the image data. I tried this same thing on my tumblr theme (http://www.tumblr.com/theme/32199) but ended up not using it.
Demo: http://jsfiddle.net/ThinkingStiff/vXWvz/
HTML:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script src="http://thinkingstiff.com/scripts/get-image-data.js"></script>
<img id="image" alt="" src="http://thinkingstiff.com/images/100x100.png" />
Script:
function initializeImage( imageElement ) {
$.getImageData( {
url: imageElement.src,
success: function( image ) {
if( !imageElement.dataset.color ) {
var canvas = document.createElement( 'canvas' ),
context = canvas.getContext( '2d' ),
width = image.width,
height = image.height;
canvas.width = width;
canvas.height = height;
context.drawImage( image, 0, 0 );
var pixels = context.getImageData( 0, 0, width, height );
for( var y = 0; y < pixels.height; y++ ) {
for( var x = 0; x < pixels.width; x++ ) {
var i = ( y * 4 ) * pixels.width + x * 4;
var avg = (
pixels.data[i]
+ pixels.data[i + 1]
+ pixels.data[i + 2]
) / 3;
pixels.data[i] = avg;
pixels.data[i + 1] = avg;
pixels.data[i + 2] = avg;
};
};
context.putImageData( pixels, 0, 0, 0, 0, pixels.width, pixels.height );
imageElement.dataset.color = imageElement.src;
imageElement.dataset.gray = canvas.toDataURL();
imageElement.src = canvas.toDataURL();
};
}
} );
};
var image = document.getElementById( 'image' );
initializeImage( image );
image.addEventListener( 'mouseover', function () {
this.src = this.dataset.color;
} );
image.addEventListener( 'mouseout', function () {
this.src = this.dataset.gray;
} );