Created
August 13, 2014 19:49
-
-
Save icholy/176246e7e4dba20aa181 to your computer and use it in GitHub Desktop.
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
<html> | |
<head> | |
<title>Change Image Color</title> | |
<style> | |
body { background-color: black; } | |
</style> | |
</head> | |
<body> | |
<canvas id="canvas"></canvas> | |
<script> | |
var can = document.getElementById('canvas'), | |
ctx = can.getContext('2d'), | |
img = new Image(), | |
rgb = [255, 100, 0]; | |
img.onload = function () { | |
// draw the image | |
can.width = img.width; | |
can.height = img.height; | |
ctx.drawImage(img, 0, 0, img.width, img.height); | |
// change the color | |
var map = ctx.getImageData(0, 0, img.width, img.height), | |
data = map.data, | |
r = rgb[0], | |
g = rgb[1], | |
b = rgb[2], | |
i; | |
for (i = 0; i < data.length; i += 4) { | |
if (data[i + 3] !== 0) { | |
data[i] = r; | |
data[i + 1] = g; | |
data[i + 2] = b; | |
} | |
} | |
ctx.putImageData(map, 0, 0); | |
} | |
img.src = 'RADAR.png'; | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment