Updated image width and height calculation code.