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

相关文章

Python3离线安装Requests模块问题

最近运维上需要在测试环境调用http的post请求,实现自动化日切,我看了下我会的编程,也就python能符合我的要求,且简单好操作。但是在实际操作过程遇到了一些问题,其中最大的就是测试...

在python中用url_for构造URL的方法

用url_for构造URL,他接受函数名作为第一个参数,也接受对应URL规则的变量部分的命名参数,未知的变量部分会添加到URL末尾作为查询参数。 构建URL而不选择直接在代码中拼URL的...

python开发游戏的前期准备

python开发游戏的前期准备

本文章面向有一定基础的python学习者,使用Pygame包开发一款简单的游戏 首先打开命令行,使用PyPI下载Pygame包(输入命令pip install pygame) 打开py...

Python实现的拟合二元一次函数功能示例【基于scipy模块】

Python实现的拟合二元一次函数功能示例【基于scipy模块】

本文实例讲述了Python实现的拟合二元一次函数功能。分享给大家供大家参考,具体如下: 背景: 使用scipy拟合一元二次函数。 参考: HYRY Studio-《用Python做科学计...

更换Django默认的模板引擎为jinja2的实现方法

本机环境 操作系统:fedora24 python版本:3.5 Django版本:1.11.1 jinja2版本:2.9.6 为何要更换 DTL 先来谈谈Django的模板引擎,找了下,...