![]() We will connect to Database and execute the query. str() is used to convert integer to string. The path to store the certificates are created using above format and inside the for loop each time a new file name is created. The file name should have the student id. Using the records we will create certificate for all. ![]() We can collect records from our student table. Path2 = "E:\\testing\\images\\certificate_12.png" # final certificateįnt1 = uetype("arial.ttf", 70) # Fontįnt2 = uetype("arial.ttf", 50)įill2 = (19, 119, 169) # colour used for data Path = "E:\\testing\\images\\certificate_b.png" # blank certificate We will use the data from the list to add to an Image. Img1 = ImageDraw.Draw(img) # create object to Drawįnt1 = uetype("arial.ttf", 70) # font for Label textįnt2 = uetype("arial.ttf", 50) # font for data textįill1 = (39, 77, 113) # colour of the Label textįill2 = (19, 119, 169) # colour of the data text Path2 = "F:\\testing\\images\\certificate_01.png" # final certificate Path = "F:\\testing\\images\\certificate.png" # blank certificate ![]() More precise alignment can be achieved by using anchor option with different values.Ĭreate certificate with details of the student The default value is la (left-ascender) or top – left corner of the image. ![]() We can specify the anchor option for the alignment of the text with xy coordinates. Img.save(path2) # Save the image in new location or path #fnt = uetype("arial.ttf", 140)įull code to read image, add text and save in given path is here. Path = "E:\\testing\\images\\cat.png" # existing image to openįnt = uetype("times.ttf", 140) # family with size MyFont = uetype('E:/PythonPillow/Fonts/FreeMono.ttf', 40)ĭ1.Creating bulk certificates using data from MySQL by Pillow in Pythonįrom PIL import Image, ImageDraw, ImageFont Exampleįrom PIL import Image, ImageDraw, ImageFont We can either load fonts directly from the system by passing the full path to the function, or we can use the ImageFont to load a TrueType font. There are numerous ways to select the font used for writing on the image. If you save the above program as Example.py and execute, it will add the given text on it, and displays it using the standard PNG display utility, as follows − Selecting the font We can pass multiple other parameters to this method. You can write text on images by passing the location of the text, the text itself and the color of the text.
0 Comments
Leave a Reply. |