Reputation: 561
I'm trying to create an image with some text using Python Pil
library. But the problem is generated text having spots around the character. How can I remove that? (Black spots will be clearly visible if you move the screen little backwards.)
This is my code :
font_size=14
font = ImageFont.truetype(MEDIA_FONT, font_size)
box_image_height = 80
box_image_width = 250
box_image = Image.new(
'RGB',
(box_image_width, box_image_height),
(255,255,255)
)
draw = ImageDraw.Draw(box_image)
draw.text((30, box_image_height-34),contact_no , font=font, fill="green")
Output:
Upvotes: 1
Views: 761
Reputation: 752
Changing box_image to the following might fix it, the 'RGBA' parameter instead of 'RGB' adds the possibility for transparency in the image, and will make the image a png image instead of a jpg image.
box_image = Image.new(
'RGBA',
(box_image_width, box_image_height),
(255,255,255)
)
If you want the text to be smoother, you can make the image 3x as wide, and 3x as high, then add this code to resize it to the original size.
img_resized = image.resize((YOURWIDTH/3, YOURHEIGHT/3), Image.ANTIALIAS)
Upvotes: 3