Skip to content

Instantly share code, notes, and snippets.

@paulkaplan
Created July 21, 2013 22:47
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save paulkaplan/6050309 to your computer and use it in GitHub Desktop.
Save paulkaplan/6050309 to your computer and use it in GitHub Desktop.
Getting fabric.js to work with Retina screens
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);
}
@lustdante
Copy link

Thank you for saving my day!

@whipsterCZ
Copy link

Thanks!

@vitaly-zdanevich
Copy link

For which version of Fabric?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment