Last active
August 29, 2015 14:15
-
-
Save plugn/d49c6ea0f48e72e547dc to your computer and use it in GitHub Desktop.
canvas filter
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
function process(img) { | |
var oCanvas = document.getElementById('canvas'), | |
oCtx = oCanvas.getContext("2d"), | |
width, height, imgData, dataURL; | |
width = img.offsetWidth; | |
height = img.offsetHeight; | |
oCanvas.width = width; | |
oCanvas.height = height; | |
oCtx.filter = 'invert(100%)'; | |
oCtx.drawImage(img, 0, 0); | |
// ImageData.data is PNG BLOB usable as shown @ http://stackoverflow.com/a/26595628 | |
// imgData = oCtx.getImageData(0, 0, width, height); | |
dataURL = oCanvas.toDataURL(); | |
return dataURL; | |
} | |
function start() { | |
var src = document.querySelector('img'), | |
pre = document.querySelector('pre'); | |
if (src) { | |
pre.innerHTML = process(src); | |
} else { | |
console.warn(' Something Went Wrong '); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment