# Scale Background Image

**URL:** <https://forum.kirupa.com/t/scale-background-image/217416>\
**Category:** flash\
**Created:** [February 26, 2007, 8:48pm UTC](https://forum.kirupa.com/t/scale-background-image/217416 "2007-02-26T20:48:25Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![earph](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/earph/32/79_2.png) [@earph](https://forum.kirupa.com/u/earph)\
**Post date:** [February 26, 2007, 8:48pm UTC](https://forum.kirupa.com/t/scale-background-image/217416/1 "2007-02-26T20:48:25Z")

</div>

I managed to run across this code which resizes my background image to the size of the window, but it does not work well with vertical formatted images. It cuts off the bottom of the image when using this code.

```auto

stop();
	Stage.scaleMode = "noScale";
	Stage.align = "TL";
	
	bg.onResize = function() {
	   var imageAspectRatio = bg._width / bg._height;
	   var stageAspectRatio = Stage.width / Stage.height;
	   if (stageAspectRatio >= imageAspectRatio) {
		  bg._width = Stage.width;
		  bg._height = Stage.width / imageAspectRatio;
	   } else {
		  bg._height = Stage.height;
		  bg._width = Stage.height * imageAspectRatio;
	   }
	   bg._x = Stage.width /2 ;
	   bg._y = Stage.height /2;
	};
	Stage.addListener(bg);
	bg.onResize();

```

How could I change this code so that it will change the aspect ratio if there is a vertical image instead of horizontal? Instead of it cutting off the bottom of the image, I would rather it scale to the height and leave blanks areas to the right and left.

Thanks…
