У меня немного проблема с масштабированием моих изображений до должным образом предопределенного размера. Мне было интересно - поскольку это чисто математика, если есть какой-то общий логический алгоритм, который работает на каждом языке (PHP, ActionScript, Javascript и т.д.) Для пропорционального масштабирования изображений.
Я использую это в данный момент:
var maxHeight = 300;
var maxWidth = 300;
var ratio:Number = height / width;
if (height > maxHeight) {
height = maxHeight;
width = Math.round(height / ratio);
}
else if(width > maxWidth) {
width = maxWidth;
height = Math.round(width * ratio);
}
Но это работает неправильно. Изображения масштабируются пропорционально, конечно, но размер не установлен равным 300 (по ширине или по высоте). Это имеет смысл, но мне было интересно, есть ли у нас простудный, простой способ масштабирования изображений пропорционально.