Last active
January 4, 2016 20:59
-
-
Save rvighne/8677360 to your computer and use it in GitHub Desktop.
Most browsers do not make it easy to draw perfect 1-pixel-wide lines; usually they are two pixels wide and weaker than the color you want. This little hack fixes that and some image smoothing problems.
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 pixelPerfect(ctx) { | |
ctx.translate(0.5, 0.5); // so pixels with odd coordinates snap to nearest physical pixel | |
ctx.imageSmoothingEnabled = false; // may need polyfill for safari | |
} | |
// Call pixelPerfect with your canvas context (obtained by getContext) as argument, and happy whole-pixel drawing! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment