Determine image dimensions correctly.