posted on 2023-05-03 20:57 read(766) comment(0) like(9) collect(4)
Hello everyone, I am Kongkong star. In this article, I will share with you how to add text watermark to pictures through Python's PIL library .
PIL is the abbreviation of Python Imaging Library, which is one of the commonly used image processing libraries in Python language. It provides a wealth of image processing functions, including operations such as opening, saving, cropping, rotating, and scaling, and supports multiple image formats.
pip install pillow
pip show pillow
Name: Pillow
Version: 9.4.0
Summary: Python Imaging Library (Fork)
Home-page: https://python-pillow.org
Author: Alex Clark (PIL Fork Author)
Author-email: aclark@python-pillow.org
License: HPND
Requires:
Required-by: image, imageio, matplotlib, pytesseract, wordcloud
from PIL import Image, ImageDraw, ImageFont
local = '/Users/kkstar/Downloads/video/pic/'
image = Image.open(local+"demo.jpg")
draw = ImageDraw.Draw(image)
text = '@空空star'
font = ImageFont.truetype('STHeitiMedium.ttc', size=80)
# 通过名称设置颜色-黄色
color = 'yellow'
# 通过RGB值设置颜色-红色
color = (255, 0, 0)
# 通过RGBA值设置颜色-白色
color = (255,255,255,0)
# 通过十六进制设置颜色-绿色
color = '#6FE000'
text_width, text_height = draw.textsize(text, font)
x = 30
y = 30
x = image.width-text_width-30
y = image.height-text_height-30
Adjust the x and y values at other positions. This 30 is set by me like this, you can also adjust it according to your own preferences.
draw.text((x, y), text, font=font, fill=color)
image.save(local+'image_with_watermark.jpg')
Author:kkkkkkkkkkdsdsd
link:http://www.pythonblackhole.com/blog/article/293/9475b96c291b1bc3c37f/
source:python black hole net
Please indicate the source for any form of reprinting. If any infringement is discovered, it will be held legally responsible.
name:
Comment content: (supports up to 255 characters)
Copyright © 2018-2021 python black hole network All Rights Reserved All rights reserved, and all rights reserved.京ICP备18063182号-7
For complaints and reports, and advertising cooperation, please contact vgs_info@163.com or QQ3083709327
Disclaimer: All articles on the website are uploaded by users and are only for readers' learning and communication use, and commercial use is prohibited. If the article involves pornography, reactionary, infringement and other illegal information, please report it to us and we will delete it immediately after verification!