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

相关文章

Python pickle模块用法实例

python的pickle模块实现了基本的数据序列和反序列化。通过pickle模块的序列化操作我们能够将程序中运行的对象信息保存到文件中去,永久存储;通过pickle模块的反序列化操作,...

python xml解析实例详解

python xml解析 first.xml  <info> <person > <id>1</id> <n...

python3中类的继承以及self和super的区别详解

python中类的继承: 子类继承父类,及子类拥有了父类的 属性 和 方法。 python中类的初始化都是__init__()。所以父类和子类的初始化方式都是__init__(),但是如...

解决pytorch GPU 计算过程中出现内存耗尽的问题

Pytorch GPU运算过程中会出现:“cuda runtime error(2): out of memory”这样的错误。通常,这种错误是由于在循环中使用全局变量当做累加器,且累加...

python使用Flask操作mysql实现登录功能

python使用Flask操作mysql实现登录功能

用到的一些知识点:Flask-SQLAlchemy、Flask-Login、Flask-WTF、PyMySQL 这里通过一个完整的登录实例来介绍,程序已经成功运行,在未登录时拦截了suc...