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与R语言的简要对比

Python与R语言的简要对比

数据挖掘技术日趋成熟和复杂,随着互联网发展以及大批海量数据的到来,之前传统的依靠spss、SAS等可视化工具实现数据挖掘建模已经越来越不能满足日常需求,依据美国对数据科学家(data s...

Python 多个图同时在不同窗口显示的实现方法

Python的matplotlib包可以轻松的将数据可视化,博主最近遇到了一个问题,博主想同时在两个窗口展示两张图,但是代码运行结果总是显示一张图,把当前的图删掉之后才能显示另一张图。网...

Python实现报警信息实时发送至邮箱功能(实例代码)

Python实现报警信息实时发送至邮箱功能(实例代码)

Python实现报警信息实时发送至邮箱功能,具体内容如下所示: 程序设计 实现代码 cpu.py # -*- coding: utf-8 -*- import psutil im...

python的pdb调试命令的命令整理及实例

python的pdb调试命令的命令整理及实例 一、命令整理 pdb调试命令 完整命令 简写命令 描述...

python实现输入数字的连续加减方法

不用库,写了很久,一直出bug,到网上一搜,可以直接输入之后,eval(str)即可得到结果! eval程序如下: s=input("请输入要运算的数字") print("The r...