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中metaclass元类的创建与使用

举例讲解Python中metaclass元类的创建与使用

元类是可以让你定义某些类是如何被创建的。从根本上说,赋予你如何创建类的控制权。 元类也是一个类,是一个type类。   元类一般用于创建类。在执行类定义时,解释器必须要知道这个...

Python的log日志功能及设置方法

引入:Python中有个logging模块可以完成相关信息的记录,在debug时用它往往事半功倍 一、日志级别(从低到高): DEBUG :详细的信息,通常只出现在诊断问题上 INFO:...

python 3.6.5 安装配置方法图文教程

python 3.6.5 安装配置方法图文教程

Windowns操作系统中安装Python,供大家参考,具体内容如下 一.下载Python 1.python 官网 下载安装包 2.选择版本 我这里用安装版(64位) 二...

Python使用sorted对字典的key或value排序

sorted函数 sorted(iterable,key,reverse) iterable 待排序的可迭代对象 key 对应的是个函数, 该函数用来决定选取用哪些值来进行排...

Python3.4实现从HTTP代理网站批量获取代理并筛选的方法示例

本文实例讲述了Python3.4实现从HTTP代理网站批量获取代理并筛选的方法。分享给大家供大家参考,具体如下: 最近在写爬虫,苦于不采用代理的情况下,默认的IP不出几分钟就被封了,故而...