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 Qt5实现窗体跟踪鼠标移动

我就废话不多说了, 直接上代码吧! from PyQt5.Qt import * import sys class Window(QWidget): def __init...

Django框架会话技术实例分析【Cookie与Session】

本文实例讲述了Django框架会话技术。分享给大家供大家参考,具体如下: 会话技术 1、Cookie 客户端会话技术(数据存储在客户端) 以key-value的形式进行存储...

Python3内置模块之json编解码方法小结【推荐】

Python3中我们利用内置模块 json 解码和编码 JSON对象 ,JSON(JavaScript Object Notation)是指定 RFC 7159(废弃了RFC 4627)...

在Python中用keys()方法返回字典键的教程

 keys()方法返回在字典中的所有可用的键的列表。 语法 以下是keys()方法的语法: dict.keys() 参数    ...

python sorted函数的小练习及解答

前两天学习了一下socket编程,在向某大神请教问题时被嫌弃了,有一种还没学会走就想跑的感觉。大神说我现在的水平应该去做一些像是操作文件、序列号等的小练习来加深理解。下面是他给我出的小练...