calculate scale correctly for images