Need to save varaible to DB
I don't even know enough about jquery to be dangerous. However, I ran across this script to pick background color. I can't seem to figure out which variable i need to save the rgba color. I tried grabbing "rgba" but it doesn't work. Can somebody help me put here?
<script>
;(function($){
$.fn.canvasify = function(f){ // faster than dynamically converting a pixel at a time
return this.map(function(){
if (this.nodeName=="IMG"){
var canvas=$('<canvas>')
this.src = this.src // IE fix
$(this).one('load',function(){
canvas.attr({width:this.width,height:this.height})
canvas[0].getContext('2d').drawImage(this,0,0,this.width,this.height)
$(this).replaceWith(canvas)
})
return canvas[0]
}else{
return this
}
})
}
function Rgba(rgba){
this.rgba = rgba
this.toString = function(){ return "rgba("+Array.prototype.join.call(this.rgba,',')+")" }
}
$.Event.prototype.rgba=function(){
var x = this.offsetX || (this.pageX - $(this.target).offset().left),
y = this.offsetY || (this.pageY - $(this.target).offset().top),
nodeName = this.target.nodeName
if (nodeName==="CANVAS")
return new Rgba(this.target.getContext('2d').getImageData(x,y,1,1).data)
else if (nodeName==="IMG"){
var canvas=document.createElement("canvas")
canvas.width=1
canvas.height=1
canvas.getContext('2d').drawImage(this.target,x,y,1,1,0,0,1,1)
return new Rgba(canvas.getContext('2d').getImageData(0,0,1,1).data)
} else return null
}
})(jQuery)
$(function() {
$("figure").append("<p class=rgba>")
$('img').canvasify().click(demo)
// $('img').click(demo)
function demo(e){
var rgba=e.rgba(),
figure = $(this).parent()
figure.css('background-color',rgba).find("p").text(rgba)
}
});
</script>
<style>
p.rgba {
background:white;
color:black;
border:1px solid red;
min-height:20px;
}
</style>