Added image resize, factored out util functions