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中的random()方法的使用介绍

 random()方法返回一个随机浮点数r,使得0是小于或等于r 以及r小于1。 语法 以下是random()方法的语法: random ( ) 注意:此函数是无法直...

python和shell变量互相传递的几种方法

python -> shell: 1.环境变量 复制代码 代码如下:import os  var=123或var='123'os.environ['var']=str(v...

Python实现的银行系统模拟程序完整案例

本文实例讲述了Python实现的银行系统模拟程序。分享给大家供大家参考,具体如下: 银行系统模拟程序 1、概述 ​ 使用面向对象思想模拟一个简单的银行系统,具备的功能:管理员...

Python unittest模块用法实例分析

本文实例讲述了Python unittest模块用法。分享给大家供大家参考,具体如下: python的unittest模块提供了一个测试框架,只要我们写一个继承unittest.Test...

python中日期和时间格式化输出的方法小结

本文实例总结了python中日期和时间格式化输出的方法。分享给大家供大家参考。具体分析如下: python格式化日期时间的函数为datetime.datetime.strftime();...