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的GUI框架PySide的安装配置教程

Python的GUI框架PySide的安装配置教程

(一)说在前面     Python自带了GUI模块Tkinter,只是界面风格有些老旧。另外就是各种GUI框架了。    ...

Python 实现引用其他.py文件中的类和类的方法

#HelloWorld是文件名称,Hello是类 from HelloWorld import Hello 调用,Hello类的方法: >>> h = Hel...

浅析Git版本控制器使用

浅析Git版本控制器使用

本篇内容通过GitHub仓库创建过程以及创建连接后的上传与下载,详细介绍了Git版本控制器使用情况,来看下。 首先介绍一下什么是Git:git是目前最流行的版本控制系统,属于分布式版本控...

django框架防止XSS注入的方法分析

本文实例讲述了django框架防止XSS注入的方法。分享给大家供大家参考,具体如下: XSS 是常见的跨站脚本攻击,而且这种类型的错误很不容易被发现或者被开发人员忽视,当然django...

python中的&&及||的实现示例

首先说明一下,在python中是没有&&及||这两个运算符的,取而代之的是英文and和or。其他运算符没有变动。 接着重点要说明的是python中的a.any(),我之所以会涉及到这个函...