/ Published in: ActionScript 3
Usage:
<code>
var newDimensions:Object = resize(800,600,320,200);
</code>
This can be adapted to pretty much any language...
<code>
var newDimensions:Object = resize(800,600,320,200);
</code>
This can be adapted to pretty much any language...
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
/** * resize * Take input diemnsion and return the resulting dimensions using a ratio * @param _w initial width * @param _h initial height * @param _targetW targeted width * @param _targetH targeted height * @param _ratio set the ratio manually instead of automatically detecting it (0) * @return An object containing both resulting dimensions :object.width,object.height */ function resize(_w:Number,_h:Number,_targetW:Number,_targetH:Number,_ratio:Number = 0):Object { var ratio:Number = (_ratio ==0) ? _w / _h : _ratio; var rW:Number = _targetW; var rH:Number = _targetH; if (ratio >= 1) { rH = _targetW / ratio; if (rH > _targetH) { rH = _targetH; rW = rH * ratio; } }else { rW = _targetH * ratio; if (rW > _targetW) { rW = _targetW; rH = rW / ratio; } } var newDimensions:Object = {width:rW,height:rH }; return newDimensions; }