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程序设计有所帮助。

相关文章

PyCharm使用教程之搭建Python开发环境

PyCharm使用教程之搭建Python开发环境

PyCharm是JetBrains系列产品的一员,也是现在最好用的IDE。PyCharm维持了JetBrains一贯高度智能的作风,简要枚举如下: 独特的本地VCS系统 强大...

使用pandas对两个dataframe进行join的实例

需求: 两个文件,一个文件为统计报表,里面含有手机号,另一个文件为手机号段归属地,含有手机号码前七位对应的地区。需要对统计报表进行处理,将手机号所在的归属地加入到统计报表中,使用pand...

手把手教你python实现SVM算法

手把手教你python实现SVM算法

什么是机器学习 (Machine Learning)       机器学习是研究计算机怎样模拟或实现人类的学习行为,以获取新的知识或技能...

python实现在pandas.DataFrame添加一行

实例如下所示: from pandas import * from random import * df = DataFrame(columns=('lib', 'qty1', 'q...

Python字符串拼接、截取及替换方法总结分析

本文实例讲述了Python字符串拼接、截取及替换方法。分享给大家供大家参考,具体如下: python字符串连接 python字符串连接有几种方法,我开始用的第一个方法效率是最低的,后来看...