python - How do I properly set DPI when saving a pillow image? -


i trying create images programatically on python using pillow library i'm having problems image quality of text inside image.

i want save image generate png, i'm setting dpi when saving according this, whether save dpi=(72,72) or dpi=(600,600) visually looks same.

my code doing following:

from pil import image, imagedraw, imagefont  def generate_empty_canvas(width, height, color='white'):     size = (width, height)     return image.new('rgb', size, color=color)  def draw_text(text, canvas):     font = imagefont.truetype('verdana.ttf', 10)     draw = imagedraw.draw(canvas)     if '\n' not in text:         draw.text((0, 0), text, font=font, fill='black')     else:         draw.multiline_text((0, 0), text, font=font, fill='black')  def create_sample():     text = 'aaaaaaaaaaaaaaaaaa\nbbbbbbbbbbbbbbbbbbbbbbb\nccccccccccccccccccccc'     canvas = generate_empty_canvas(200, 50)     draw_text(text, canvas)     canvas.save('low_quality.png', dpi=(72, 72))     canvas.save('high_quality.png', dpi=(600, 600)) 

the low_quality.png is:

image dpi=72

the high_quality.png is:

image dpi=600

as it's visible images quality didn't change. doing wrong here?

where set dpi image has dpi=600?

the dpi values metadata on computer images. give hints on how display or print image.

printing 360×360 image 360 dpi result in 1×1 inches printout.

a simplified way explain it: dpi setting recommends zoom level image.

saving other dpis not change content of image. if want larger image use larger size , larger font.


Comments