0
0
0xbadc0ffee2020-08-09 16:54:34
Python
0xbadc0ffee, 2020-08-09 16:54:34

How can this code snippet be improved?

Below is a code snippet that draws text on an image.
Is there any way to improve this code snippet? In terms of further maintenance / clean code?

from PIL import Image
from PIL import ImageFont
from PIL import ImageDraw

class drawer():
    def __init__(self,image):
        self.image = Image.open(image)
        self.draw = ImageDraw.Draw(self.image)
        self.font = ImageFont.truetype("18991.ttf", 16)
    def draw(self,text,x,y):
        self.draw.text((x,y),text,(255,255,255),font=self.font)
    def save(self,path):
        self.image.save(path)

if __name__ == '__main__':
    img = drawer("sample.jpg")
    img.draw("15:51",50,1230)
    img.save("Ex.jpg")

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dr. Bacon, 2020-08-09
@0xbadc0ffee

Rewrite to function.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question