Skip to content

Commit

Permalink
Added option to different backgrounds and line colors
Browse files Browse the repository at this point in the history
  • Loading branch information
lindell committed May 17, 2014
1 parent 436d208 commit 8eafc7e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
25 changes: 12 additions & 13 deletions JsBarcode.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,20 @@
canvas.width = binary.length*options.width+2*options.quite;
canvas.height = options.height;

//Paint the canvas white
ctx.fillStyle = "#fff";
ctx.fillRect(0,0,canvas.width,canvas.height);
//Paint the canvas
ctx.clearRect(0,0,canvas.width,canvas.height);
if(options.backgroundColor){
ctx.fillStyle = options.backgroundColor;
ctx.fillRect(0,0,canvas.width,canvas.height);
}

//Creates the barcode out of the encoded binary
ctx.fillStyle = options.lineColor;
for(var i=0;i<binary.length;i++){

var x = i*options.width+options.quite;

if(binary[i] == "1"){
ctx.fillStyle = "#000";
}
else{
ctx.fillStyle = "#fff";
}

ctx.fillRect(x,0,options.width,options.height);
ctx.fillRect(x,0,options.width,options.height);
}
}

//Grab the dataUri from the canvas
Expand All @@ -60,7 +57,9 @@
width: 2,
height: 100,
quite: 10,
format: "CODE128"
format: "CODE128",
backgroundColor:"#fff",
lineColor:"#000"
};

})(jQuery);
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ $(object).JsBarcode(string,options);
####The default options:
````javascript
{
width: 2,
width: 2,
height: 100,
quite: 10,
format: "CODE128"
format: "CODE128",
backgroundColor:"#fff",
lineColor:"#000"
}
````

Expand Down

0 comments on commit 8eafc7e

Please sign in to comment.