It’s been a while since this I posted my question, but here’s a solution that works fine for me. Hope it can help you too!
/Mats
————————————-
MaxWidth = 650; //Max width in pixels
MaxHeight = 400; //Max height in pixels
PixWidth = source.width;
PixHeight = source.height;
factor = MaxWidth / PixWidth;
NewWidth = transform.scale[0] * factor;
NewHeight = transform.scale[1] * factor;
if(NewHeight >= MaxHeight) {
faktor = MaxHeight / PixHeight;
NewWidth = transform.scale[0] * factor;
NewHeight = transform.scale[1] * factor;
}
[NewWidth,NewHeight]
——————————–