python实现图片变亮或者变暗的方法

yipeiwu_com5年前Python基础

本文实例讲述了python实现图片变亮或者变暗的方法。分享给大家供大家参考。具体实现方法如下:

import Image
# open an image file (.jpg or.png) you have in the working folder
im1 = Image.open("angelababy.jpg")
# multiply each pixel by 0.9 (makes the image darker)
# works best with .jpg and .png files, darker < 1.0 < lighter
# (.bmp and .gif files give goofy results)
# note that lambda is akin to a one-line function
im2 = im1.point(lambda p: p * 0.5)
# brings up the modified image in a viewer, simply saves the image as
# a bitmap to a temporary file and calls viewer associated with .bmp
# make certain you have associated an image viewer with this file type
im2.show()
# save modified image to working folder as Audi2.jpg
im2.save("angelababy2.jpg")

运行效果如下所示:

希望本文所述对大家的Python程序设计有所帮助。

相关文章

Python时间差中seconds和total_seconds的区别详解

如下所示: import datetime t1 = datetime.datetime.strptime("2017-9-06 10:30:00", "%Y-%m-%d %H:...

Python 模拟动态产生字母验证码图片功能

Python 模拟动态产生字母验证码图片功能

模拟动态产生字母验证码图片 模拟生成验证码,首先要做的是生成随机的字母,然后对字母进行模糊处理。这里介绍一下 Python 提供的 Pillow 模块。 Pillow PIL:Pytho...

Python字符串处理函数简明总结

返回被去除指定字符的字符串 默认去除空白字符 删除首尾字符:str.strip([char]) 删除首字符:str.lstrip([char]) 删除尾字符str.strip([ch...

Python 类,property属性(简化属性的操作),@property,property()用法示例

本文实例讲述了Python 类,property属性(简化属性的操作),@property,property()用法。分享给大家供大家参考,具体如下: property属性的创建方式有两...

解决python3运行selenium下HTMLTestRunner报错的问题

修改HTMLTestRunner.py以支持python3+ 搜索到的结果整理 修改一: 在python shell里输入 >>>import HTMLTestRunn...