acornejo / jquery-cropbox

jQuery Cropbox plugin
http://acornejo.github.io/jquery-cropbox/
MIT License
345 stars 82 forks source link

Retina support #89

Open gblazex opened 7 years ago

gblazex commented 7 years ago
  getDataURL: function () {
    var canvas = document.createElement('canvas'), ctx = canvas.getContext('2d');
    var pixelRatio = window.devicePixelRatio || 1;
    canvas.width  = this.options.width  * pixelRatio;
    canvas.height = this.options.height * pixelRatio;
    ctx.scale(pixelRatio, pixelRatio);
    ctx.drawImage(this.$image.get(0), this.result.cropX, this.result.cropY, 
                  this.result.cropW, this.result.cropH, 0, 0, 
                  this.options.width, this.options.height);
    return canvas.toDataURL();
  },

see: https://tristandunn.com/2014/01/24/rendering-svg-on-canvas/