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如何使用k-means方法将列表中相似的句子归类

Python如何使用k-means方法将列表中相似的句子归类

前言 由于今年暑假在学习一些自然语言处理的东西,发现网上对k-means的讲解不是很清楚,网上大多数代码只是将聚类结果以图片的形式呈现,而不是将聚类的结果表示出来,于是我将老师给的代码和...

python 利用turtle库绘制笑脸和哭脸的例子

python 利用turtle库绘制笑脸和哭脸的例子

我就废话不多说了,直接上代码吧! import turtle turtle.pensize(5) turtle.pencolor("yellow") turtle.fillcolor...

python实现五子棋游戏

python实现五子棋游戏

本文实例为大家分享了python实现五子棋游戏的具体代码,供大家参考,具体内容如下 话不多说,直接上代码: 全部工程文件,在GitHub:五子棋 效果预览: #!/usr/bin/...

替换python字典中的key值方法

比如有一个 a = {‘a': 1} 希望变为 a = {‘b' :1} 即:在保留value不变的情况下,替换key值 目前能想到的实现方案是 a[‘b'] = a.p...

使用11行Python代码盗取了室友的U盘内容

使用11行Python代码盗取了室友的U盘内容

序言 那个猥琐的家伙整天把个U盘藏着当宝,到睡觉了就拿出来插到电脑上。 我决定想个办法看他U盘里都藏了什么,直接去抢U盘是不可能的,骗也是不可能的。那不是丢我Python程序员的脸? 我...