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 log取对数详解

log()方法返回x的自然对数,对于x>0。 语法 以下是log()方法的语法: import math math.log( x ) 注意:此函数是无法直接访问的,所以我...

python3.6 如何将list存入txt后再读出list的方法

python3.6 如何将list存入txt后再读出list的方法

今天遇到一个需求,就是将一个list文件读取后,存入一个txt配置文件。存入时,发现list文件无法直接存入,必须转为str模式。 但在读取txt时,就无法恢复成list类型来读取了(准...

Python元组操作实例分析【创建、赋值、更新、删除等】

Python元组操作实例分析【创建、赋值、更新、删除等】

本文实例讲述了Python元组操作。分享给大家供大家参考,具体如下: #coding=utf8 ''''' 元组是跟列表非常相近的另一种容器类型。 元组是一种不可变类型,一旦创建不可...

Python Excel处理库openpyxl使用详解

openpyxl是一个第三方库,可以处理xlsx格式的Excel文件。pip install openpyxl安装。 读取Excel文件 需要导入相关函数 from openpy...

python自定义异常实例详解

python自定义异常实例详解          本文通过两种方法对Python 自定义异常进行讲解,第一...