ClearCode

Deformer

May 18th, 2022
1,371
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.74 KB | None | 0 0
  1. from PIL import Image, ImageOps
  2.  
  3. class Deformer():
  4.     def getmesh(self,img):
  5.         w,h = img.size
  6.         # # define a shape in the original image
  7.         # source_shape = (0,0,0,h,w - 1000,h,w,0)
  8.         # # define a rectangle in the new image
  9.         # target_rect = (0,0,w,h) # left,top,right,bottom
  10.        
  11.         left = ((0,0,w // 2, h),(0, 0, 0, h, w // 2, h, w // 2 , 0))
  12.         right = ((w // 2,0,w,h),(w // 2, 0, w // 2, h, 0, h, 0 , 0))
  13.         flip = ((w // 2, 0, w, h ),(w // 2, h, w // 2, 0, w, 0, w - 1000 , h))
  14.  
  15.         # return all the shapes
  16.         return [left,right]
  17.  
  18. # image import
  19. image = Image.open('picture.jpg')
  20. deform = ImageOps.deform(image,Deformer())
  21. deform.save('17.png')
  22.  
  23. # more advanced example: https://www.pythoninformer.com/python-libraries/pillow/imageops-deforming/
Advertisement
Add Comment
Please, Sign In to add comment