Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # разворачивает изображение, внутри исходного на некоторый угол angle,
- # используя color_name в качестве цвета бэкграунда
- @staticmethod
- def rotate_image(source_image_path, source_image_name, angle, back_color='black', dest_image_path=''):
- img = Image.open(source_image_path)
- dest_image_path = ImageStructure.gen_name_from_source(source_image_path, source_image_name, dest_image_path,
- 'rotate-')
- angle = random.randrange(0, 30)
- rotate = img.convert('RGBA').rotate(int(angle), expand=1)
- background = Image.new('RGBA', rotate.size, back_color)
- out = Image.composite(rotate, background, rotate)
- w, h = img.size
- out.convert(img.mode).resize((int(w), int(h)), Image.ANTIALIAS)
- out.save(dest_image_path, 'jpeg')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement