Hi there,
I have searched this forum and online but can’t find a solution to the problem I am having.
I need to scale images so that they always fit within my browser but also retain their aspect ratio. All other examples I have seen at some point either the width or height is cropped off by the edge of the browser. I need my images to always stay inside but also I do not want them to ever scale above 100% i.e. no enlargement.
I have some code that is pretty bad. It works but causes a massive bug where the image goes crazy.
http://www.ourtestsite.org/test/cp_test/
I found this one already
http://www.yapiodesign.com/blog/2007/02/11/scale-image-proportionally/
however the images don’t stay within 100% scale and also get cropped off.
Any help is really appreciated and I will try and help out anyone else as much as I can.
The code I have is like this
if(mainTL.allImages._width > Stage.width){
mainTL.allImages._width = Stage.width;
mainTL.allImages._height = mainTL.allImages._width * imageRatio;
} else if(mainTL.allImages._height > Stage.height){
mainTL.allImages._height = Stage.height;
mainTL.allImages._width = mainTL.allImages._height * imageRatio;
} else if(mainTL.allImages._width < Stage.width){
mainTL.allImages._width = Stage.width;
mainTL.allImages._height = mainTL.allImages._width * imageRatio;
} else if(mainTL.allImages._height < Stage.height){
mainTL.allImages._height = Stage.height;
mainTL.allImages._width = mainTL.allImages._height * imageRatio;
}
Thanks
Will