ImageWidth and ImageHeight were inverted in calculateImage function