Miscellaneous helpfunctions such as image scaling.