python实现图片变亮或者变暗的方法

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

相关文章

Numpy掩码式数组详解

数据很大形况下是凌乱的,并且含有空白的或者无法处理的字符,掩码式数组可以很好的忽略残缺的或者是无效的数据点。掩码式数组由一个正常数组与一个布尔式数组组成,若布尔数组中为Ture,则表示正...

Django日志模块logging的配置详解

前言 Django对于日志输出的信息是很完善的,request的信息,setting配置,trackback的信息,一应俱全,足够我们调试了。但是在线上环境,如果让用户看到这些信息,是很...

对python的输出和输出格式详解

对python的输出和输出格式详解

输出 1. 普通的输出 # 打印提示 print('hello world') 用print()在括号中加上字符串,就可以向屏幕上输出指定的文字。比如输出'hello, world...

python元组和字典的内建函数实例详解

本文实例讲述了python元祖和字典的内建函数。分享给大家供大家参考,具体如下: 元组Tuple 元组是序列类型一种,也是不可变类型数据结构,对元组修改后会生成一个新的元组。所以Tupl...

python smtplib模块实现发送邮件带附件sendmail

本文实例为大家分享了python smtplib实现发送邮件的具体代码,供大家参考,具体内容如下 #!/usr/bin/env python # -*- coding: UTF-8...