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制作数据导入导出工具

python 2.6编写,自己瞎写的,备用 ''' Export and Import ElasticSearch Data. Simple Example At __mai...

Python实现简单求解给定整数的质因数算法示例

本文实例讲述了Python实现简单求解给定整数的质因数算法。分享给大家供大家参考,具体如下: 接着做题遇到求解质因数分解的问题,思想很简单,就是需要遍历从1到该整数本身,并且判断当数字为...

Python+Django搭建自己的blog网站

Python+Django搭建自己的blog网站

一、前言 1.1.环境 python版本:3.6 Django版本:1.11.6 1.2.预览效果 最终搭建的blog的样子,基本上满足需求了。框架搭好了,至于CSS,可以根据自己喜好随...

Python面向对象class类属性及子类用法分析

本文实例讲述了Python面向对象class类属性及子类用法。分享给大家供大家参考,具体如下: class类属性 class Foo(object): x=1.5 foo=Foo...

python线程池的实现实例

直接上代码:复制代码 代码如下:# -*- coding: utf-8 -*- import Queue import threadingimport urllibimport urll...