Stage.align and Stage.scale(X,Y) algorithms

Hello, I’m after a good way to take a image scale it to where:[LIST=1]
[]the image scale propotionately ([COLOR=Red]image.scaleY == image.scaleX[/COLOR]);
[
]the image must scale to fit the browser, But.
[*]the image must not leave empty areas of the stage exposed ([COLOR=Red]upscale the image if needed to cover blank stage area exposed, which will clip off a end of the image and thats where Stage.align comes in[/COLOR])[/LIST]the stage.align will help give scale orientation, meaning from what direction will the image scale. This is important since this can cause a few problems with centering of the image upon rescale and you also want to know what end is most likely to get clipped off in the event that the image needs to upscale to cover blank stage areas.

as I have it now

_imageHolder is a hypothetical image and stage is a reference to the stage.
I know this algorithm is not a best practice and it don’t cover the stage completely. Any help would be great.


            if((_imageHolder.width >= stage.stageWidth) && (_imageHolder.height >= stage.stageHeight)){
                if(_imageHolder.width >= stage.stageWidth){
                    _imageHolder.width = stage.stageWidth;
                    _imageHolder.scaleY = _imageHolder.scaleX;
                }else if(_imageHolder.height >=  stage.stageHeight){
                    _imageHolder.height = stage.stageHeight;
                    _imageHolder.scaleX = _imageHolder.scaleY;
                }
            }else if((_imageHolder.width <= stage.stageWidth) && (_imageHolder.height <= stage.stageHeight)){
                if(_imageHolder.width < stage.stageWidth){
                    _imageHolder.width = stage.stageWidth;
                    _imageHolder.scaleY = _imageHolder.scaleX;
                }else if(_imageHolder.height < stage.stageHeight){
                    _imageHolder.height = stage.stageHeight;
                    _imageHolder.scaleX = _imageHolder.scaleY;
                }
            }
        }

This event will be in a function that fires when the stage rescales or when the image loads.
Also what is a good idea to deal with the stage.align problems that can come up?