Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # anti_alias.py >>> i thank you all again so much for the quick response as to help
- from PIL import Image, ImageDraw
- '''
- ADAPTIVE = 1
- AFFINE = 0
- ANTIALIAS = 1
- BICUBIC = 3
- BILINEAR = 2
- CONTAINER = 2
- CUBIC = 3
- DEBUG = 0
- EXTENT = 1
- FLIP_LEFT_RIGHT = 0
- FLIP_TOP_BOTTOM = 1
- FLOYDSTEINBERG = 3
- LINEAR = 2
- MESH = 4
- NEAREST = 0
- ORDERED = 1
- PERSPECTIVE = 2
- QUAD = 3
- RASTERIZE = 2
- '''
- def antialias():
- def o(z):
- return int(z+z*0.1)
- img = image.resize([o(ww), o(hh)], Image.RASTERIZE)
- return img.resize((ww, hh), Image.ANTIALIAS)
- def draw_ellipse(image, bounds):
- draw = ImageDraw.ImageDraw(image)
- x,y,x2,y2 = bounds
- for w,color in [(40,'white'), (0,'green')]:
- if not w:
- draw.ellipse([x-19, y-19, x2+19, y2+19], fill='white')
- draw.ellipse((x-w, y-w, x2+w, y2+w), fill=color)
- if w:
- draw.ellipse([x-21, y-21, x2+21, y2+21], fill='black')
- enlarge = 1
- ww,hh = (700, 300)
- image = Image.new(mode='RGBA', size=(ww,hh), color='green')
- ellipse_box = [50, 50, 300, 250]
- draw_ellipse(image, ellipse_box)
- image = antialias()
- ellipse_box[0] += 350
- ellipse_box[2] += 350
- enlarge = 0
- draw_ellipse(image, ellipse_box)
- dir=r"C:/pydemo/test/"
- file = 'anti_alias.png'
- image.save(dir+file, optimize=True)
- import webbrowser
- webbrowser.open(dir+file)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement