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

相关文章

在python3.5中使用OpenCV的实例讲解

在python3.5中使用OpenCV的实例讲解

最近在OpenCV的官方文档上看到一个人脸识别的示例代码,想要实现。由于我之前下好的OpenCV3.1中并不自带相关的函数,即opencv2/contrib/contrib.hpp这个文...

python之拟合的实现

python之拟合的实现

一、多项式拟合 多项式拟合的话,用的的是numpy这个库的polyfit这个函数。那么多项式拟合,最简单的当然是,一次多项式拟合了,就是线性回归。直接看代码吧 import nump...

读取json格式为DataFrame(可转为.csv)的实例讲解

有时候需要读取一定格式的json文件为DataFrame,可以通过json来转换或者pandas中的read_json()。 import pandas as pd import j...

Django对接支付宝实现支付宝充值金币功能示例

Django对接支付宝实现支付宝充值金币功能示例

很多网站里都有金币、积分之类的虚拟货币,获取这些往往需要充值。那么问题来了,如何在Django中对接支付宝实现支付宝充值金币的功能呢?网上很多资料都是电商的,那些都会带有订单系统之类比较...

python微信公众号之关键词自动回复

最近忙国赛的一个项目,我得做一个微信公众号。功能就是调数据并回复给用户,需要用户发送给公众号一个关键词,通过关键词自动回复消息。 这时就是查询微信公众平台文档了,地址如下: 文档 按照它...