ericdrowell / KineticJS

KineticJS is an HTML5 Canvas JavaScript framework that extends the 2d context by enabling canvas interactivity for desktop and mobile applications.
http://www.kineticjs.com
3.98k stars 752 forks source link

Poor Quality when downscaling SVG Images and export to dataUrl #933

Closed confile closed 10 years ago

confile commented 10 years ago

I tested KineticJS 5.10 with an svg image:

var stage = new Kinetic.Stage({
    container: 'container',
    width: 400,
    height: 400
});
var layer = new Kinetic.Layer();
stage.add(layer);

var img=new Image();
img.onload = function () {
    var image = new Kinetic.Image({
        image: img,
        width: 100,
        height: 100,
    });
    layer.add(image);
    layer.draw();

}
img.crossOrigin="anonymous";
img.src = "https://dl.dropboxusercontent.com/u/139992952/stackoverflow/rocket.svg";

After that I downscale the image (keeping the aspect ratio):

image.scale({
 x: 30,
y: 30
});
 layer.draw();

After that I exported the stage as a jpeg image with quality 1.0:

stage.toDataURL({
            mimeType: "image/jpeg",
            quality: 1.0,
            callback: function(dataUrl) {
                // save image dataUrl to file
            }
        });

It turns out that the quality of the svg image is very bad only if you downscale it. When you increase the size the quality does not change.

confile commented 10 years ago

I made a demo here: http://jsfiddle.net/confile/p6Eey/

As you can see in the exported image the edges are very crispy and not very sharp.

lavrton commented 10 years ago

http://stackoverflow.com/a/23787397/512042