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

相关文章

Django开发中复选框用法示例

本文实例讲述了Django开发中复选框用法。分享给大家供大家参考,具体如下: 一、查询数据库遍历所有的复选框 1、python查询数据库所有的tag # 新增文章 def add(r...

python list转矩阵的实例讲解

如下所示: <pre name="code" class="python">#list转矩阵,矩阵列合并 x = [[1.2,2.2,1.4],[1.3,2.4,2.1]...

Python自然语言处理 NLTK 库用法入门教程【经典】

本文实例讲述了Python自然语言处理 NLTK 库用法。分享给大家供大家参考,具体如下: 在这篇文章中,我们将基于 Python 讨论自然语言处理(NLP)。本教程将会使用 Pyth...

Python中的jquery PyQuery库使用小结

pyquery库是jQuery的Python实现,可以用于解析HTML网页内容,使用方法:复制代码 代码如下:from pyquery import PyQuery as pq1、可加载...

Python列表原理与用法详解【创建、元素增加、删除、访问、计数、切片、遍历等】

Python列表原理与用法详解【创建、元素增加、删除、访问、计数、切片、遍历等】

本文实例讲述了Python列表原理与用法。分享给大家供大家参考,具体如下: 列表的基本认识 列表简介 列表的创建 基本语法[]创建 list()创建...