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

[Question] Stage resizing on export - v5.1.1 (2014-05-29) Use "stage.width(value)" function instead. #949

Closed josesayago closed 10 years ago

josesayago commented 10 years ago

Hello, I've found two differences between v5.1.1 (2014-05-02) and v5.1.1 (2014-05-29) which I'd like to better understand:

I upgraded from v4.7.4 some months ago, that time I asked how to resize the stage on export, which was correctly answered here: #788

However, since I upgraded to v5.0.1 and subsequently v5.1.1 (2014-05-02), resizing and scaling stage before exporting didn't work. I tried doing this:

stage.setScale({ 
    x: params.zoom, 
    y: params.zoom 
});
stage.setSize({ 
    width: params.width, 
    height: params.height 
});

Then browsing on StackOverflow I found this: KineticJS: How do I scale a Stage where it seems parameters have changed again, and now stage sizing and scaling should be set like this:

stage.scaleX( params.zoom );
stage.scaleY( params.zoom );
stage.size({ 
     width: params.width, 
     height: params.height 
});

It seems both work without any issues, however in v4.7.4 exported images were correctly resized and scaled while in v5.0.1 and v5.1.1 (2014-05-02) were not. However, I kept looking and found you've recently updated v5.1.1 (2014-05-29) which now correctly resizes and scales stages as in v4.7.4 but this time there is a warning message displayed on my debugging console: Kinetic warning: Can not change with of layer. Use "stage.width(value)" function instead.

Which points to the new KineticJS v5.1.1 library but nowhere in my source code. I'm wondering what's going on here. It's not a big deal because stage is now correctly exported but I hope this won't break anything else in the future.

I'm attaching two images where you can see the differences between scaling and resizing:

v4.7.4 & v5.1.1 (2014-05-29) - Correct right

v5.0.1 & v5.1.1 (2014-05-02) - Incorrect wrong

Best regards, José SAYAGO.

lavrton commented 10 years ago

Can you create any jsfiddle?

josesayago commented 10 years ago

Hello @lavrton, I've made two fiddles but I was unable to reproduce the same behavior as explained here. The only difference with my app is I'm exporting images through AJAX, and forcing them to be downloaded using PHP.

In my app I export using toDataURL and toImage, the issue explained before just happens on the image resulting from the toDataURL + AJAX + PHP download.

jsFiddle Export in v5.0.1 jsFiddle Export in v5.1.1

I'll close this topic because I was unable to reproduce it, I'll keep investigating my own app to see if I can figure this out.

Cheers, José SAYAGO.