Advertisement
here2share

# anti_alias.py ^ 05.2019

May 29th, 2019
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.28 KB | None | 0 0
  1. # anti_alias.py >>> i thank you all again so much for the quick response as to help
  2.  
  3. from PIL import Image, ImageDraw
  4.  
  5. '''
  6. ADAPTIVE = 1
  7. AFFINE = 0
  8. ANTIALIAS = 1
  9. BICUBIC = 3
  10. BILINEAR = 2
  11. CONTAINER = 2
  12. CUBIC = 3
  13. DEBUG = 0
  14. EXTENT = 1
  15. FLIP_LEFT_RIGHT = 0
  16. FLIP_TOP_BOTTOM = 1
  17. FLOYDSTEINBERG = 3
  18. LINEAR = 2
  19. MESH = 4
  20. NEAREST = 0
  21. ORDERED = 1
  22. PERSPECTIVE = 2
  23. QUAD = 3
  24. RASTERIZE = 2
  25. '''
  26.  
  27. def antialias():
  28.     def o(z):
  29.         return int(z+z*0.1)
  30.     img = image.resize([o(ww), o(hh)], Image.RASTERIZE)
  31.     return img.resize((ww, hh), Image.ANTIALIAS)
  32.  
  33. def draw_ellipse(image, bounds):
  34.     draw = ImageDraw.ImageDraw(image)
  35.     x,y,x2,y2 = bounds
  36.     for w,color in [(40,'white'), (0,'green')]:
  37.         if not w:
  38.             draw.ellipse([x-19, y-19, x2+19, y2+19], fill='white')
  39.         draw.ellipse((x-w, y-w, x2+w, y2+w), fill=color)
  40.         if w:
  41.             draw.ellipse([x-21, y-21, x2+21, y2+21], fill='black')
  42.  
  43. enlarge = 1
  44. ww,hh = (700, 300)
  45. image = Image.new(mode='RGBA', size=(ww,hh), color='green')
  46.  
  47. ellipse_box = [50, 50, 300, 250]
  48. draw_ellipse(image, ellipse_box)
  49.  
  50. image = antialias()
  51.  
  52. ellipse_box[0] += 350
  53. ellipse_box[2] += 350
  54.  
  55. enlarge = 0
  56. draw_ellipse(image, ellipse_box)
  57.  
  58. dir=r"C:/pydemo/test/"
  59. file = 'anti_alias.png'
  60. image.save(dir+file, optimize=True)
  61.  
  62. import webbrowser
  63. webbrowser.open(dir+file)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement