그림의 영역을 새로운 변수로자를 수 있습니다. 이 경우 원래 이미지에서 120x120 픽셀 상자를 잘라 냈습니다. 90도 회전 한 다음 원본에 붙여 넣습니다.
from PIL import Image
img = Image.open('./image.jpg')
sub_image = img.crop(box=(200,0,320,120)).rotate(90)
img.paste(sub_image, box=(200,0))
그래서 좀 더 생각하고이 회전하기 전에 잘라낸 화상에 원형 마스크를 적용하는 기능을 제작. 이상한 효과가없는 임의의 각도를 허용합니다.
def circle_rotate(image, x, y, radius, degree):
img_arr = numpy.asarray(image)
box = (x-radius, y-radius, x+radius+1, y+radius+1)
crop = image.crop(box=box)
crop_arr = numpy.asarray(crop)
# build the cirle mask
mask = numpy.zeros((2*radius+1, 2*radius+1))
for i in range(crop_arr.shape[0]):
for j in range(crop_arr.shape[1]):
if (i-radius)**2 + (j-radius)**2 <= radius**2:
mask[i,j] = 1
# create the new circular image
sub_img_arr = numpy.empty(crop_arr.shape ,dtype='uint8')
sub_img_arr[:,:,:3] = crop_arr[:,:,:3]
sub_img_arr[:,:,3] = mask*255
sub_img = Image.fromarray(sub_img_arr, "RGBA").rotate(degree)
i2 = image.copy()
i2.paste(sub_img, box[:2], sub_img.convert('RGBA'))
return i2
i2 = circle_rotate(img, 260, 60, 60, 45)
i2
시도는에 연결하지 않고 문제의 사진을 포함합니다. – gowrath
done sir, [이 이미지] (http://i.stack.imgur.com/PxGtN.png) –
이미지의 복사본을 만듭니다. 자르기를 원하는 영역으로 자르고 회전시키고 회전하여 원본에 붙여 넣으십시오. 그게 효과가 있니? – gowrath