Re: [Flashcoders] Scaling Up an Image in Proportion to width or height

2007-04-16 Thread James Tu
I found some code online which I turned into a function...  This  
should give you the scale whether you are scaling up or down.  You  
tell it the area you want your mc to fit into and it will give you a  
number back...all you have to do is then use that number...example:  
mc._xscale = mc._yscale = number_returned_from_function.


Maybe this helps out a bit?

function fitToDimension( sourceWidth:Number, sourceHeight:Number,  
targetWidth:Number, targetHeight:Number ):Number {


if ( sourceWidth/targetWidth > sourceHeight/targetHeight ) {
//aspect ratio is determined by width
return (targetWidth*100/sourceWidth);
} else {
//aspect ratio is determined by height
return (targetHeight*100/sourceHeight);
}

}

-James



On Mar 28, 2007, at 10:28 AM, {reduxdj} wrote:

I know how to scale an image down... what's the formula for scaling  
up too?


For instance, i want my images to be in proportion and at least 500  
pixels wide.


Thanks,
Patrick

___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com




___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


RE: [Flashcoders] Scaling Up an Image in Proportion to width or height

2007-03-29 Thread Jesse Graupmann
I bet this just adds to the confusion... but who doesn't love a one-liner?





//  1. MATH - ONE LINE

var w = 800;
var h = 600;
var n = 1024; 

w = ((h *= n/w) && n);





//  2. MATH - TWO LINES (same as above)

var w = 800;
var h = 600;
var n = 1024;

h *= n/w; // adjust h based on w
w = n;// set w





//  3. SIMPLE MC

mc._width = 200;
mc._yscale = mc._xscale;






//  4. BOUNDS

// stage listener
sl = {}
Stage.addListener( sl );
sl.onResize = onStageResize;
onStageResize ();

// on resize
function onStageResize () 
{
var newScale = ratioScaling ( photo_mc, Stage.width, Stage.height,
640, 480, 1024, 768, true );
trace( 'newScale: ' + newScale );
}

// resize function
function ratioScaling ( mc:MovieClip, W:Number, H:Number, minW:Number,
minH:Number, maxW:Number, maxH:Number, useMax:Boolean ) : Number 
{
// set within bounds
mc._width = Math.max ( Math.min( maxW, W ), minW );
mc._height = Math.max ( Math.min( maxH, H ), minH );

// set and return the smallest ratio, 
// unless useMax is true, then choose largest ratio. 
return mc._xscale = mc._yscale = Math[(useMax)?'max':'min'](
mc._xscale, mc._yscale );
}





_

Jesse Graupmann
www.jessegraupmann.com
www.justgooddesign.com/blog/
_

___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


Re: [Flashcoders] Scaling Up an Image in Proportion to width or height

2007-03-29 Thread Paul V.
Here is the method I use,  It works for simply rescaling, or conditional
rescaling (i.e.
if(object._width > yourMaxWidth){ rescaleDimensions();};

function rescaleDimensions(){
oldWidth = object._width;
oldHeight = object._height;

object._width = yourNewWidth;
object._height = ((yourNewWidth*oldHeight)/oldWidth);

//thats it.  Simple.
}

Heres the algebra:
x/y  =  new x/ new y
therefore   x*new y = y* new x
thereforenew y = (y * new x)/x

Note: I didn't read the original post, just answering according to the
subject title.

Hope I was of some help.  (becasue I have gotten losts of it along the way
too)

Paul Vdst.

- Original Message - 
From: "Steven Sacks | BLITZ" <[EMAIL PROTECTED]>
To: 
Sent: Thursday, March 29, 2007 1:24 PM
Subject: RE: [Flashcoders] Scaling Up an Image in Proportion to width or
height


Why would you do that, though?  You're adding an extra calculation for
no reason.  It's inefficient and unnecessary.

And I'm not setting _height to _width divided by ratio, but _width TIMES
ratio.




> -Original Message-
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] On Behalf
> Of Steve Abaffy
> Sent: Thursday, March 29, 2007 11:46 AM
> To: flashcoders@chattyfig.figleaf.com
> Subject: RE: [Flashcoders] Scaling Up an Image in Proportion
> to width or height
>
> Yes but you could do it like this
>
> You resize the _width:
> _width = Math.max(newWidth, 500);
> You set _height to the _width * ratio:
> _height = _width * (1/ratio);
> Which is the same thing as
> _height = _width / ratio;
>
>
>
> This would be (_width/_height * _height) this cancels the
> _height leaving
> you with just _width.
>
>
> -Original Message-
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] On Behalf
> Of Hershell
> Bryant
> Sent: Thursday, March 29, 2007 1:58 PM
> To: flashcoders@chattyfig.figleaf.com
> Subject: RE: [Flashcoders] Scaling Up an Image in Proportion
> to width or
> height
>
> That'd do it...except that you need to define var ratio:Number =
> _height/_width.
>
> If var ratio:Number = _width/_height, then _width * ratio = (_width *
> _width)/_heightThat ain't right.
>
>
> -Original Message-
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] On Behalf
> Of Steven Sacks
> | BLITZ
> Sent: Thursday, March 29, 2007 9:42 AM
> To: flashcoders@chattyfig.figleaf.com
> Subject: RE: [Flashcoders] Scaling Up an Image in Proportion
> to width or
> height
>
> Simple.
>
> You solve for the ratio:
>
> var ratio:Number = _width / _height;
>
>
> You resize the _width:
>
> _width = Math.max(newWidth, 500);
>
>
> You set _height to the _width * ratio:
>
> _height = _width * ratio;
>
>
> fin.
> ___
> Flashcoders@chattyfig.figleaf.com
> To change your subscription options or search the archive:
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>
> Brought to you by Fig Leaf Software
> Premier Authorized Adobe Consulting and Training
> http://www.figleaf.com
> http://training.figleaf.com
>
>
> ___
> Flashcoders@chattyfig.figleaf.com
> To change your subscription options or search the archive:
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>
> Brought to you by Fig Leaf Software
> Premier Authorized Adobe Consulting and Training
> http://www.figleaf.com
> http://training.figleaf.com
>
>
>
> ___
> Flashcoders@chattyfig.figleaf.com
> To change your subscription options or search the archive:
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>
> Brought to you by Fig Leaf Software
> Premier Authorized Adobe Consulting and Training
> http://www.figleaf.com
> http://training.figleaf.com
>
___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


RE: [Flashcoders] Scaling Up an Image in Proportion to width or height

2007-03-29 Thread Steven Sacks | BLITZ
Why would you do that, though?  You're adding an extra calculation for
no reason.  It's inefficient and unnecessary.

And I'm not setting _height to _width divided by ratio, but _width TIMES
ratio.


 

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf 
> Of Steve Abaffy
> Sent: Thursday, March 29, 2007 11:46 AM
> To: flashcoders@chattyfig.figleaf.com
> Subject: RE: [Flashcoders] Scaling Up an Image in Proportion 
> to width or height
> 
> Yes but you could do it like this
> 
> You resize the _width:
> _width = Math.max(newWidth, 500);
> You set _height to the _width * ratio:
> _height = _width * (1/ratio);
> Which is the same thing as
> _height = _width / ratio;
> 
> 
> 
> This would be (_width/_height * _height) this cancels the 
> _height leaving
> you with just _width.
> 
> 
> -Original Message-
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] On Behalf 
> Of Hershell
> Bryant
> Sent: Thursday, March 29, 2007 1:58 PM
> To: flashcoders@chattyfig.figleaf.com
> Subject: RE: [Flashcoders] Scaling Up an Image in Proportion 
> to width or
> height
> 
> That'd do it...except that you need to define var ratio:Number =
> _height/_width.
> 
> If var ratio:Number = _width/_height, then _width * ratio = (_width *
> _width)/_heightThat ain't right.
> 
> 
> -Original Message-
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] On Behalf 
> Of Steven Sacks
> | BLITZ
> Sent: Thursday, March 29, 2007 9:42 AM
> To: flashcoders@chattyfig.figleaf.com
> Subject: RE: [Flashcoders] Scaling Up an Image in Proportion 
> to width or
> height
> 
> Simple.
> 
> You solve for the ratio:
> 
> var ratio:Number = _width / _height;
> 
> 
> You resize the _width:
> 
> _width = Math.max(newWidth, 500);
> 
> 
> You set _height to the _width * ratio:
> 
> _height = _width * ratio;
> 
> 
> fin.
> ___
> Flashcoders@chattyfig.figleaf.com
> To change your subscription options or search the archive:
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
> 
> Brought to you by Fig Leaf Software
> Premier Authorized Adobe Consulting and Training
> http://www.figleaf.com
> http://training.figleaf.com
> 
> 
> ___
> Flashcoders@chattyfig.figleaf.com
> To change your subscription options or search the archive:
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
> 
> Brought to you by Fig Leaf Software
> Premier Authorized Adobe Consulting and Training
> http://www.figleaf.com
> http://training.figleaf.com
> 
> 
> 
> ___
> Flashcoders@chattyfig.figleaf.com
> To change your subscription options or search the archive:
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
> 
> Brought to you by Fig Leaf Software
> Premier Authorized Adobe Consulting and Training
> http://www.figleaf.com
> http://training.figleaf.com
> 
___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


RE: [Flashcoders] Scaling Up an Image in Proportion to width or height

2007-03-29 Thread Steve Abaffy
Yes but you could do it like this

You resize the _width:
_width = Math.max(newWidth, 500);
You set _height to the _width * ratio:
_height = _width * (1/ratio); 
Which is the same thing as
_height = _width / ratio;



This would be (_width/_height * _height) this cancels the _height leaving
you with just _width.


-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Hershell
Bryant
Sent: Thursday, March 29, 2007 1:58 PM
To: flashcoders@chattyfig.figleaf.com
Subject: RE: [Flashcoders] Scaling Up an Image in Proportion to width or
height

That'd do it...except that you need to define var ratio:Number =
_height/_width.

If var ratio:Number = _width/_height, then _width * ratio = (_width *
_width)/_heightThat ain't right.


-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Steven Sacks
| BLITZ
Sent: Thursday, March 29, 2007 9:42 AM
To: flashcoders@chattyfig.figleaf.com
Subject: RE: [Flashcoders] Scaling Up an Image in Proportion to width or
height

Simple.

You solve for the ratio:

var ratio:Number = _width / _height;


You resize the _width:

_width = Math.max(newWidth, 500);


You set _height to the _width * ratio:

_height = _width * ratio;


fin.
___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com



___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


RE: [Flashcoders] Scaling Up an Image in Proportion to width or height

2007-03-29 Thread Hershell Bryant
That'd do it...except that you need to define var ratio:Number =
_height/_width.

If var ratio:Number = _width/_height, then _width * ratio = (_width *
_width)/_heightThat ain't right.


-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Steven Sacks
| BLITZ
Sent: Thursday, March 29, 2007 9:42 AM
To: flashcoders@chattyfig.figleaf.com
Subject: RE: [Flashcoders] Scaling Up an Image in Proportion to width or
height

Simple.

You solve for the ratio:

var ratio:Number = _width / _height;


You resize the _width:

_width = Math.max(newWidth, 500);


You set _height to the _width * ratio:

_height = _width * ratio;


fin.
___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


RE: [Flashcoders] Scaling Up an Image in Proportion to width or height

2007-03-29 Thread Joe Wheeler
Or, if it's a movieclip you're working with you can simply:

Scale the width..

_width = 500

And then set the height using the scale property

_yscale = _xscale

Works up and down

j
 

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Steven Sacks
| BLITZ
Sent: 29 March 2007 18:42
To: flashcoders@chattyfig.figleaf.com
Subject: RE: [Flashcoders] Scaling Up an Image in Proportion to width or
height

Simple.

You solve for the ratio:

var ratio:Number = _width / _height;


You resize the _width:

_width = Math.max(newWidth, 500);


You set _height to the _width * ratio:

_height = _width * ratio;


fin.
___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training http://www.figleaf.com
http://training.figleaf.com

___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


RE: [Flashcoders] Scaling Up an Image in Proportion to width or height

2007-03-29 Thread Steven Sacks | BLITZ
Simple.

You solve for the ratio:

var ratio:Number = _width / _height;


You resize the _width:

_width = Math.max(newWidth, 500);


You set _height to the _width * ratio:

_height = _width * ratio;


fin.
___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


[Flashcoders] Scaling Up an Image in Proportion to width or height

2007-03-28 Thread {reduxdj}

I know how to scale an image down... what's the formula for scaling up too?

For instance, i want my images to be in proportion and at least 500 
pixels wide.


Thanks,
Patrick

___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com