Resizing an image to fit while maintaining aspect ratio

Here's how you resize an image (or any DisplayObject) to fit in a container while maintaining its aspect ratio. image.width=container.width; image.scaleY=image.scaleX; if(image.height>container.height){ image.height=container.height; image.scaleX=image.scaleY; } The code is pretty straight forward, making use of both its width/height and scaleX/Y properties. See it in action!

No comments:

Post a Comment