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面向对象程序设计中类的定义、实例化、封装及私有变量/方法。分享给大家供大家参考,具体如下: 1. 定义类 python中定义一个类的格式如下: class...

python将秒数转化为时间格式的实例

1、转化成时间格式 seconds =35400 m, s = divmod(seconds, 60) h, m = divmod(m, 60) print("%d:%02d:%02...

python实现csv格式文件转为asc格式文件的方法

python实现csv格式文件转为asc格式文件的方法

一、背景描述 csv格式文件是一种类似于excel的文件格式 asc格式文件是一种可以用text打开的文本文件 csv转asc本来可以用arcgis顺利完成,但由于csv数据量太大(74...

python对url格式解析的方法

本文实例讲述了python对url格式解析的方法。分享给大家供大家参考。具体分析如下: python针对url格式的解析,可根据指定的完整URL解析出url地址的各个部分 from...

python实现输入数字的连续加减方法

不用库,写了很久,一直出bug,到网上一搜,可以直接输入之后,eval(str)即可得到结果! eval程序如下: s=input("请输入要运算的数字") print("The r...