Python PIL:如何使用这样的版权徽标填充图像?
我需要通过在照片中填充版权标志来保护它们。我的操作系统是 Ubuntu 10.10 和 Python 2.6。我打算使用 PIL。
假设我有一个像这样的版权标志(你可以在 Photoshop 中轻松做到这一点) :
和这样的图片:
我想使用PIL获取如下所示的版权图片(用图案填充原始图片):
通过改变徽标的不透明度得到的最终结果:
PIL 中是否有任何函数可以做到这一点?有什么提示吗?
多谢!
I need to protect my photos by filling them with copyright logos. My OS is Ubuntu 10.10 and Python 2.6. I intend to use PIL.
Supposed I have a copyright logo like this (You can do this in Photoshop easily):
and a picture like this:
I want to use PIL to get copyrighted pictures like the following (Fill the original pic with pattern):
and Final Result by altering the opacity of logos:
Is there any function in PIL that can do this? Any hint?
Thanks a lot!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
PIL 确实有能力做到这一点。首先,您需要创建一个包含重复文本的图像。它应该是,哦,也许是你想要加水印的图像大小的两倍(因为你需要旋转它然后裁剪它)。您可以使用
Image.new()
创建这样的图像,然后循环使用ImageDraw.Draw.text()
将文本重复粘贴到其上,然后图像的rotate()
方法将其旋转 15 度左右。然后使用图像的crop()
方法将其裁剪为原始图像的大小。要首先组合它,您需要使用
ImageChops.multiply()
将水印叠加到原始图像的副本上(其不透明度为 100%),然后使用ImageChops.blend ()
以所需的不透明度将带水印的副本与原始图像混合。这应该会给你足够的信息来帮助你继续前进——如果你遇到了障碍,发布代码显示你到目前为止所得到的,并询问一个关于你遇到困难的具体问题。
PIL is certainly capable of this. First you'll want to create an image that contains the repeated text. It should be, oh, maybe twice the size of the image you want to watermark (since you'll need to rotate it and then crop it). You can use
Image.new()
to create such an image, thenImageDraw.Draw.text()
in a loop to repeatedly plaster your text onto it, and the image'srotate()
method to rotate it 15 degrees or so. Then crop it to the size of the original image using thecrop()
method of the image.To combine it first you'll want to use
ImageChops.multiply()
to superimpose the watermark onto a copy of the original image (which will have it at 100% opacity) thenImageChops.blend()
to blend the watermarked copy with the original image at the desired opacity.That should give you enough information to get going -- if you run into a roadblock, post code showing what you've got so far, and ask a specific question about what you're having difficulty with.
只是一个示例:
Just a sample: