为了正常的体验网站,请在浏览器设置里面开启Javascript功能!
首页 > python利用pil给图片打水印水印

python利用pil给图片打水印水印

2018-08-23 2页 doc 12KB 19阅读

用户头像

is_729658

暂无简介

举报
python利用pil给图片打水印水印python利用pil给图片打水印水印 python利用PIL给图片打水印水印 im = im.convert(‘RGBA’) # create a transparent layer the size of the image and draw the # watermark in that layer. layer = Image.new(‘RGBA’, im.size, (0,0,0,0)) if position == ‘tile’: for y in range(0, im.size[1], mark....
python利用pil给图片打水印水印
python利用pil给图片打水印水印 python利用PIL给图片打水印水印 im = im.convert(‘RGBA’) # create a transparent layer the size of the image and draw the # watermark in that layer. layer = Image.new(‘RGBA’, im.size, (0,0,0,0)) if position == ‘tile’: for y in range(0, im.size[1], mark.size[1]): for x in range(0, im.size[0], mark.size[0]): layer.paste(mark, (x, y)) elif position == ‘scale’: # scale, but preserve the aspect ratio ratio = min( float(im.size[0]) / mark.size[0], float(im.size[1]) / mark.size[1]) w = int(mark.size[0] * ratio) h = int(mark.size[1] * ratio) mark = mark.resize((w, h)) layer.paste(mark, ((im.size[0] - w) / 2, (im.size[1] - h) / 2)) else: layer.paste(mark, position) # composite the watermark with the layer return Image.composite(layer, im, layer) def test(): im = Image.open(‘test.png’) mark = Image.open(‘overlay.png’) watermark(im, mark, ‘tile’, 0.5).show() watermark(im, mark, ‘scale’, 1.0).show() watermark(im, mark, (100, 100), 0.5).show() if __name__ == ‘__main__’: test()
/
本文档为【python利用pil给图片打水印水印】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。 本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。 网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。

历史搜索

    清空历史搜索