enhanced image rotation function