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

yipeiwu_com6年前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判断两个文件是否相同与两个文本进行相同项筛选的方法

python判断两个文件是否相同 import hashlib def getHash(f): line=f.readline() hash=hashlib.md5()...

Django框架HttpRequest对象用法实例分析

本文实例讲述了Django框架HttpRequest对象用法。分享给大家供大家参考,具体如下: 1.URL路径参数 (1)位置参数:使用正则分组,与视图中的参数一一对应,不可换位置 例:...

python 截取 取出一部分的字符串方法

下面是split截取获得 >>> str = 'http://manualfile.s3.amazonaws.com/pdf/gti-chis-1-user-9fb...

解决python os.mkdir创建目录失败的问题

起因 今天使用 python os.mkdir创建目录时遇到的一个小问题: feature_dir = os.path.join(os.getcwd(), 'system', 'fe...

python创建子类的方法分析

本文实例讲述了python创建子类的方法。分享给大家供大家参考,具体如下: 如果你的类没有从任何祖先类派生,可以使用object作为父类的名字。经典类的声明唯一不同之处在于其没有从祖先类...