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关键字and和or用法实例

python 中的and从左到右计算表达式,若所有值均为真,则返回最后一个值,若存在假,返回第一个假值。 or也是从左到有计算表达式,返回第一个为真的值。 复制代码 代码如下: IDLE...

Python学习笔记之if语句的使用示例

前言 条件语句在实际开发中我们已经使用过几次了,在这里我们需要再次隆重的来介绍一下它,下面话不多说了,来一起看看详细的介绍吧。 if语句 顾名思义,该语句为判断语句,先来一个简单的示例...

使用Python写CUDA程序的方法

使用Python写CUDA程序有两种方式: * Numba * PyCUDA numbapro现在已经不推荐使用了,功能被拆分并分别被集成到accelerate和Numba了。 例子...

python将字典内容存入mysql实例代码

python将字典内容存入mysql实例代码

本文主要研究的是python将字典内容存入mysql,分享了实现代码,具体介绍如下。 1.背景 项目需要,用python实现了将字典内容存入本地的mysql数据库。比如说有个字典dic...

Python使用re模块实现信息筛选的方法

本文实例讲述了Python使用re模块实现信息筛选的方法。分享给大家供大家参考,具体如下: 背景 平时工作中,我们经常会处理大量的元数据(Raw Data),而一般的文件编辑器只能一次查...