mirror of
				https://github.com/python-pillow/Pillow.git
				synced 2025-11-04 18:07:51 +03:00 
			
		
		
		
	
		
			
				
	
	
		
			34 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			34 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
from __future__ import annotations
 | 
						|
 | 
						|
from PIL import Image, ImageDraw, ImageFont
 | 
						|
 | 
						|
font = ImageFont.truetype("Tests/fonts/NotoSans-Regular.ttf", 16)
 | 
						|
 | 
						|
 | 
						|
def test(anchor: ImageFont.Anchor) -> Image.Image:
 | 
						|
    im = Image.new("RGBA", (200, 100), "white")
 | 
						|
    d = ImageDraw.Draw(im)
 | 
						|
    d.line(((100, 0), (100, 100)), "gray")
 | 
						|
    d.line(((0, 50), (200, 50)), "gray")
 | 
						|
    d.text((100, 50), f"{anchor} example", "black", font, anchor)
 | 
						|
    return im
 | 
						|
 | 
						|
 | 
						|
if __name__ == "__main__":
 | 
						|
    im = Image.new("RGBA", (600, 300), "white")
 | 
						|
    d = ImageDraw.Draw(im)
 | 
						|
    anchors: list[list[ImageFont.Anchor]] = [
 | 
						|
        ["ma", "mt", "mm"],
 | 
						|
        ["ms", "mb", "md"],
 | 
						|
        ["ls", "ms", "rs"],
 | 
						|
    ]
 | 
						|
    for y, row in enumerate(anchors):
 | 
						|
        for x, anchor in enumerate(row):
 | 
						|
            im.paste(test(anchor), (x * 200, y * 100))
 | 
						|
            if x != 0:
 | 
						|
                d.line(((x * 200, y * 100), (x * 200, (y + 1) * 100)), "black", 3)
 | 
						|
            if y != 0:
 | 
						|
                d.line(((x * 200, y * 100), ((x + 1) * 200, y * 100)), "black", 3)
 | 
						|
    im.save("docs/example/anchors.webp")
 | 
						|
    im.show()
 |