天天看點

python3裡面的圖檔處理庫 pillow

在python2下用pil,而在python3下可以安裝pillow

功能,在圖檔上加上幾個字

#coding: utf-8
myPath = "./"
fontPath = "./"
inputFile = "img.jpg"
outputFile = "output.jpg"

#圖檔的基本參數擷取
try:
    from PIL import Image, ImageDraw, ImageFont, ImageEnhance
except ImportError:
    import Image, ImageDraw, ImageFont, ImageEnhance


img = Image.open('img.jpg')
draw = ImageDraw.Draw(img)
fontsize = min(img.size)/4
print(fontsize)
#用黑體可以寫中文,如果是英文字型發現不能顯示中文
myfont = ImageFont.truetype('C:/windows/fonts/simhei.ttf', size = int(fontsize))
fillcolor = "#ff0000"
width, height = img.size
draw.text((0,img.size[0]-int(fontsize)),"你好a", font=myfont, fill=fillcolor)
img.save(outputFile,'jpeg')

           

轉載于:https://www.cnblogs.com/Mysterious/p/7478232.html