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 列表转为字典的两个小方法(小结)

1、现在有两个列表,list1 = ['key1','key2','key3']和list2 = ['1','2','3'],把他们转为这样的字典:{'key1':'1','key2':...

Python requests模块实例用法

1、Requests模块说明 Requests 是使用 Apache2 Licensed 许可证的 HTTP 库。用 Python 编写,真正的为人类着想。 Python 标准库中的 u...

python操作redis方法总结

连接 Redis import redisc 连接方式:redis提供了2个方法 1:StrictRedis:实现大部分官方的命令 2:Redis:是StrictRedis的子类,用于...

Python自定义scrapy中间模块避免重复采集的方法

本文实例讲述了Python自定义scrapy中间模块避免重复采集的方法。分享给大家供大家参考。具体如下: from scrapy import log from scrapy.htt...

详解pyqt5 动画在QThread线程中无法运行问题

详解pyqt5 动画在QThread线程中无法运行问题

自己做了一个tcp工具,在学习动画的时候踩了坑,需求是根据上线变绿色,离线变灰色,如果连接断开了,则变为灰色 问题现象: 可以看到点击“连接”,“离线”的时候动画是正常的,但是当tcp...