Resize Image on PaintWeb init

35 views
Skip to first unread message

nvd_ai

unread,
Jan 10, 2011, 6:08:40 AM1/10/11
to PaintWeb discussions
Hi all,

I am having a problem to initialize paintweb while resizing an image.
here is the story:

//instantiate paintweb
var pw = new PaintWeb();
pw.config.guiPlaceholder = PWContainer;
pw.config.configFile = 'config-pw.json';

//set the default image
var pwImg = document.createElement("img");
pwImg.src = imageNode.src; //imageNode is an existing image in my
program

//non-working implementation! the image gets cropped instead of
resizing
/*pwImg.onload=function(){
pwImg.width = w;
pwImg.height = h;
}*/

pw.config.imageLoad = pwImg;


The problem is that imageNode is an image with {width:50,height=50}.
But I want that when paintWeb starts, it resizes the image to
{width:w,height:h}, which h and w are variables defined in my
program.
What happens now is that if I set the width and height of pwImg to w
and h, instead of resizing the image, it gets cropped! I tried few
different implementations, such as the one commented in the code
above, but none of them work.

I tried to find some API that resizes the canvas (not cropping). But
could not get it to work.

What's the right implementation?

Thanks,

Mihai Sucan

unread,
Jan 10, 2011, 6:28:34 AM1/10/11
to PaintWeb discussions, nvd_ai
Hello!

Unfortunately there is no API at the moment for resizing an image in
PaintWeb, but you can implement it. See PaintWeb.imageCrop(). You can add
imageResize(). Instead of using get/putImageData(), you can use
drawImage(), which allows you to specify source width and height and
destination width and height. With that you can resize the image.


Best regards,
Mihai

--
Mihai Sucan
http://www.robodesign.ro

Reply all
Reply to author
Forward
0 new messages