Fix bug for rectangular images