Created
July 21, 2013 22:47
-
-
Save paulkaplan/6050309 to your computer and use it in GitHub Desktop.
Getting fabric.js to work with Retina screens
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
if( window.devicePixelRatio !== 1 ){ | |
var c = canvas.getElement(); // canvas = fabric.Canvas | |
var w = c.width, h = c.height; | |
// Scale the canvas up by two for retina | |
// just like for an image | |
c.setAttribute('width', w*window.devicePixelRatio); | |
c.setAttribute('height', h*window.devicePixelRatio); | |
// then use css to bring it back to regular size | |
// or set it here | |
// c.setAttribute('style', 'width="'+w+'"; height="'+h+'";') | |
// or jQuery $(c).css('width', w); | |
// $(c).css('width', w); | |
// $(c).css('height', h); | |
// finally set the scale of the context | |
c.getContext('2d').scale(window.devicePixelRatio, window.devicePixelRatio); | |
} |
Thanks!
For which version of Fabric?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you for saving my day!