Problems reading raster size

95 views
Skip to first unread message

Paolo Mistrangelo

unread,
Jan 8, 2014, 12:40:06 PM1/8/14
to pap...@googlegroups.com
Hi list,
I'm having a random error trying to read raster size addressing paperscript variables from a js script . 

From Firebug:




This is the script...sometimes works, sometimes not. Either on Chrome and FF, trying to open the same images....quite strange

window.paper.project.activeLayer.removeChildren();
var imagePath = $('input[type=file]').val();
imagePath=imagePath.replace("C:\\fakepath\\","");
rastr = new window.paper.Raster(imagePath);

var wi=rastr.width;
var he=rastr.height;
var vw=window.paper.view.size.width;
var vh=window.paper.view.size.height;
if (he>wi) {
var scala=vh/he;
} else {
var scala=vw/wi;
}
window.paper.view.zoom=scala;
rastr.position =window.paper.project.view.center;
window.paper.project.view.draw();

I even tried to check the isInserted() method, but no luck!

Any help ?
Thanks

Paolo

Jürg Lehni

unread,
Jan 8, 2014, 1:26:41 PM1/8/14
to pap...@googlegroups.com
that's probably happening because you access the raster before it's loaded?

Try wrapping the code in a raster.onLoad = function() {} block.
> --
> You received this message because you are subscribed to the Google Groups "Paper.js" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to paperjs+u...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.

Paolo Mistrangelo

unread,
Jan 8, 2014, 6:46:58 PM1/8/14
to pap...@googlegroups.com
Thanks Jürg ...it works now!  But in Chrome I had to change view.size to view.viewSize (I still didn't get the difference between the two!)
Is the onLoad event inherited from js? I didn't know I can use it on raster object cause wasn't in your references....anyway thanks again.

Paolo
Reply all
Reply to author
Forward
0 new messages