Home  >  Article  >  Backend Development  >  Learning pillow knowledge points in Python

Learning pillow knowledge points in Python

不言
不言Original
2018-05-02 16:00:461621browse

This article will give you a note on learning pillow knowledge points in Python so that you can have an understanding of the learning direction of pillow. Friends who are interested can learn from it.

This series is intended to record some interesting programs and summarize them.

Question source:

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

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

Today this program adds numbers to a picture, similar to the small red dots on the QQ avatar, but this one is static.

The first thing to use is the pillow image library.

The general idea is to open the image through Image.open(), set the format of the information to be drawn, ImageDraw.Draw() generates the modified instance, and then modify it through the text() method.

The procedure is as follows:

from PIL import Image, ImageDraw, ImageFont


def 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)

##

The above is the detailed content of Learning pillow knowledge points in Python. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn