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向图片里添加文字

本文实例为大家分享了python图片添加文字的具体代码,供大家参考,具体内容如下 #!/usr/bin/python #-*-coding:utf-8-*- from PIL im...

解决Django中调用keras的模型出现的问题

笔者小白在用Django写一个表格单据图片的识别应用的时候,遇到了调用基于Tensorflow的keras模型出错的问题。 出现的错误信息类似于以下: ValueError: Ten...

wxPython实现画图板

wxPython实现画图板

本文实例为大家分享了wxPython画图板展示的具体代码,供大家参考,具体内容如下 #coding:GBK ''' Created on 2012-3-22 @author: cWX...

Python3 串口接收与发送16进制数据包的实例

如下所示: import serial import string import binascii s=serial.Serial('com4',9600) s.open() #接收...

使用Python批量修改文件名的代码实例

使用Python批量修改文件名的代码实例

这两天在整理一些文章,但是文件夹中每个文章没有序号会看起来很乱,所以想着能不能用Python写一个小脚本。 于是乎,参考了多方资料,简单写了下面几行代码 import osdef...