Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. # разворачивает изображение, внутри исходного на некоторый угол angle,
  2. # используя color_name в качестве цвета бэкграунда
  3. @staticmethod
  4. def rotate_image(source_image_path, source_image_name, angle, back_color='black', dest_image_path=''):
  5. img = Image.open(source_image_path)
  6. dest_image_path = ImageStructure.gen_name_from_source(source_image_path, source_image_name, dest_image_path,
  7. 'rotate-')
  8. angle = random.randrange(0, 30)
  9. rotate = img.convert('RGBA').rotate(int(angle), expand=1)
  10. background = Image.new('RGBA', rotate.size, back_color)
  11. out = Image.composite(rotate, background, rotate)
  12. w, h = img.size
  13. out.convert(img.mode).resize((int(w), int(h)), Image.ANTIALIAS)
  14. out.save(dest_image_path, 'jpeg')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement