refact code of rotate image problem