Python中pillow知識點學習

來源:互聯網
上載者:User
本文給大家通過一篇Python中pillow知識點學習的筆記內容讓大家對pillow有一個學習方向的有一個認識,有興趣的朋友學習下。

此系列意在記錄於一些有趣的程式及對其的總結。

問題來源:

https://github.com/Yixiaohan/show-me-the-code

https://github.com/HT524/500LineorLess_CN

今天這個程式於一張圖片中添加數字,類似於qq頭像上的小紅點,只不過這個是靜態。

首先使用的是pillow這個映像庫。

總體思路是通過Image.open()開啟映像,設定要繪製的資訊的格式,ImageDraw.Draw()產生被修改的執行個體,再通過text()方法進行修改。

程式如下:

from PIL import Image, ImageDraw, ImageFontdef pic_add_num(image):  my_font = ImageFont.truetype(r"C:\windows\Fonts\simsun.ttc", size=40)  color = "red"  width, height = image.size  position = (width-40, 0)  draw = ImageDraw.Draw(image)    draw.text(position, "99", font=my_font, fill=color)   image.save("add_num.jpg")if __name__ == "__main__":  img = Image.open("universe.jpg")  pic_add_num(img)

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.