2000字范文,分享全网优秀范文,学习好帮手!
2000字范文 > python使用PIL模块实现给图片打水印办法

python使用PIL模块实现给图片打水印办法

时间:2018-11-11 09:49:54

相关推荐

python使用PIL模块实现给图片打水印办法

后端开发|Python教程

python,PIL模块,图片,打水印

后端开发-Python教程

本文实例讲述了python使用PIL模块实现给图片打水印的方法。分享给大家供大家参考。具体实现方法如下:

棋牌源码金币版,ubuntu系统操作步骤,爬虫 top50,php 积分墙,seo推广助手lzw

import Image, ImageEnhancedef 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 imdef watermark(im, mark, position, opacity=1): """Adds a watermark to an image.""" if opacity < 1: mark = reduce_opacity(mark, opacity) if im.mode != RGBA: 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 == ile: 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 posite(layer, im, layer)def test(): im = Image.open( est.jpg) mark = Image.open(overlay.jpg) watermark(im, mark, ile, 0.5).show() watermark(im, mark, scale, 1.0).show() watermark(im, mark, (100, 100), 0.5).show()if __name__ == \__main__: test()

accoin数字金融整站源码,vscode数据科学模式,ubuntu电脑分屏,tomcat放jsp文件,爬虫安全,xampp php5.2,佛山seo排名哪里不错,织梦官网装饰公司网站源码,公司设计模板lzw

delphi 取色器源码,vscode颜色显示有延迟,Ubuntu的感悟,tomcat获取虚拟路径,python爬虫复制,php前端java后台,温州整站seo联系方式,图片小说直播网站源码,新织梦后台增加模板lzw

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。