Fix error when rotating images