简体   繁体   English

Python PIL:如何用这样的版权标志填充图像?

[英]Python PIL: How to FIll a Image with a copyright logo like this?

I need to protect my photos by filling them with copyright logos.我需要用版权标志来保护我的照片。 My OS is Ubuntu 10.10 and Python 2.6.我的操作系统是 Ubuntu 10.10 和 Python 2.6。 I intend to use PIL .我打算使用PIL

Supposed I have a copyright logo like this ( You can do this in Photoshop easily ):假设我有一个这样的版权标志(你可以在 Photoshop 中轻松地做到这一点):

水印标志

and a picture like this:和这样的图片:

原图

I want to use PIL to get copyrighted pictures like the following (Fill the original pic with pattern):我想使用 PIL 来获取受版权保护的图片,如下所示(用图案填充原始图片):

受版权保护的图片

and Final Result by altering the opacity of logos:通过更改徽标的不透明度获得最终结果:

最后结果

Is there any function in PIL that can do this? PIL中是否有任何function可以做到这一点? Any hint?有什么提示吗?

Thanks a lot!非常感谢!

PIL is certainly capable of this. PIL当然有能力做到这一点。 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, then ImageDraw.Draw.text() in a loop to repeatedly plaster your text onto it, and the image's rotate() method to rotate it 15 degrees or so.您可以使用Image.new()创建这样的图像,然后在循环中使用 ImageDraw.Draw.text( ImageDraw.Draw.text()将文本重复粘贴到其上,并使用图像的rotate()方法将其旋转 15 度左右。 Then crop it to the size of the original image using the crop() method of the image.然后使用图像的crop()方法将其裁剪为原始图像的大小。

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) then ImageChops.blend() to blend the watermarked copy with the original image at the desired opacity.要首先组合它,您需要使用ImageChops.multiply()将水印叠加到原始图像的副本上(它将具有 100% 的不透明度),然后ImageChops.blend()将水印副本与原始图像混合图像在所需的不透明度。

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.这应该为您提供足够的信息以继续前进 - 如果您遇到障碍,发布代码以显示您到目前为止所获得的内容,并询问您遇到困难的具体问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM