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.梯度下降 1)什么是梯度下降? 因为梯度下降是一种思想,没有严格的定义,所以用一个比喻来解释什么是梯度下降。 简单来说,梯度下降就是从山顶找一条最短的路走到山脚最低的地方。但是因为...

对python中的logger模块全面讲解

logging模块介绍 Python的logging模块提供了通用的日志系统,熟练使用logging模块可以方便开发者开发第三方模块或者是自己的Python应用。同样这个模块提供不同的日...

Pyramid添加Middleware的方法实例

假设我们要添加一个我们自己的Middleware,用来记录每次请求的日志下面就是一个符合规范的Middleware, 构造函数中接受一个WSGI APP, __call__返回一个WSG...

python 数据的清理行为实例详解

python 数据的清理行为实例详解 数据清洗主要是指填充缺失数据,消除噪声数据等操作,主要还是通过分析“脏数据”产生的原因和存在形式,利用现有的数据挖掘手段去清洗“脏数据”,然后转化为...

python实现查找excel里某一列重复数据并且剔除后打印的方法

本文实例讲述了python实现查找excel里某一列重复数据并且剔除后打印的方法。分享给大家供大家参考。具体分析如下: 在python里面excel的简单读写操作我这里推荐使用xlrd(...