惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Security Archives - TechRepublic
Security Archives - TechRepublic
O
OpenAI News
W
WeLiveSecurity
Hacker News: Ask HN
Hacker News: Ask HN
Hacker News - Newest:
Hacker News - Newest: "LLM"
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
T
Troy Hunt's Blog
L
LINUX DO - 最新话题
SecWiki News
SecWiki News
Schneier on Security
Schneier on Security
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
N
News and Events Feed by Topic
TaoSecurity Blog
TaoSecurity Blog
H
Heimdal Security Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
P
Palo Alto Networks Blog
Project Zero
Project Zero
Attack and Defense Labs
Attack and Defense Labs
C
CXSECURITY Database RSS Feed - CXSecurity.com
T
Tor Project blog
Scott Helme
Scott Helme
T
Threat Research - Cisco Blogs
Simon Willison's Weblog
Simon Willison's Weblog
Spread Privacy
Spread Privacy
Cisco Talos Blog
Cisco Talos Blog
T
Threatpost
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
The Last Watchdog
The Last Watchdog
Google DeepMind News
Google DeepMind News
P
Privacy & Cybersecurity Law Blog
Know Your Adversary
Know Your Adversary
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
L
Lohrmann on Cybersecurity
Cloudbric
Cloudbric
I
Intezer
The Hacker News
The Hacker News
L
LINUX DO - 热门话题
AI
AI
B
Blog
S
Securelist
P
Proofpoint News Feed
量子位
Jina AI
Jina AI
V2EX - 技术
V2EX - 技术
T
The Exploit Database - CXSecurity.com
酷 壳 – CoolShell
酷 壳 – CoolShell
Recent Commits to openclaw:main
Recent Commits to openclaw:main
C
CERT Recently Published Vulnerability Notes
J
Java Code Geeks
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻

博客园 - 末世纪狂潮

[导入]Pylogs v1.14beta (正式支持Django 1.0) 发布 [导入]Django中动态改变ImageField和FileField中文件的上传路径 [导入]Tech·ED 2008 票到了。。。 [导入]ASP.NET获取客户端IP地址的几点补充[转载] - 末世纪狂潮 - 博客园 [导入]Windows Live Mail不能启动的解决办法 - 末世纪狂潮 [导入]Linux Mint中文语言包 [导入]XPS 1530安装MAC OsX 10.5.2指南 [导入]奥运加油,中国加油 [导入]IE7打不开微软的首页了? [导入]linux下常用格式的压缩与解压方法 [导入]Pylogs v1.12beta发布 test live write write blog 用C#写一个简单的WINDOWS服务程序 测试tb .NET中实现无刷新客户端联动下拉菜单 "百万首页"深度思考 QQ天气预报代码 QQ登录没反应解决方法,及新版QQ的一个BUG 要开始学JAVA了,郁闷中。。。
[导入]利用PIL生成水印图片或文字
末世纪狂潮 · 2008-07-06 · via 博客园 - 末世纪狂潮

      最近在做一个图片网站,要处理很多图片,处理图片少不了加水印了,呵呵。PIL用得不熟,在网上找了一圈,加上自己稍微修改了一下,用起来也算方便,生成效果也不错,呵呵,支持透明的png水印图片,透明度和水印位置都可以很方便的调整。大笑



import Image, ImageEnhance
POSITION = ('LEFTTOP','RIGHTTOP','CENTER','LEFTBOTTOM','RIGHTBOTTOM')
PADDING = 10
MARKIMAGE = 'pylogs.png'
def reduce_opacity(im, opacity):
"""Returns an image with reduced opacity."""
assert opacity >= 0 and opacity <= 1
if im.mode != 'RGBA':
im = im.convert('RGBA')
else:
im = im.copy()
alpha = im.split()[3]
alpha = ImageEnhance.Brightness(alpha).enhance(opacity)
im.putalpha(alpha)
return im
def watermark(imagefile, markfile, position=POSITION[4], opacity=1):
"""Adds a watermark to an image."""
im = Image.open(imagefile)
mark = Image.open(markfile)
if opacity < 1:
mark = reduce_opacity(mark ...

文章来源:http://oteam.cn/2008/7/6/use-pil-create-watermark/