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+Django+pycharm+mysql 搭建首个web项目详解

python+Django+pycharm+mysql 搭建首个web项目详解

本文实例讲述了python+Django+pycharm+mysql 搭建首个web项目。分享给大家供大家参考,具体如下: 前面的文章记录了环境搭建的过程,本节记录首个web项目调试 首...

在Linux下使用Python的matplotlib绘制数据图的教程

在Linux下使用Python的matplotlib绘制数据图的教程

如果你想要在Linxu中获得一个高效、自动化、高质量的科学画图的解决方案,应该考虑尝试下matplotlib库。Matplotlib是基于python的开源科学测绘包,基于python软...

利用Python产生加密表和解密表的实现方法

利用Python产生加密表和解密表的实现方法

序言: 这是我第一次写博客,有不足之处,希望大家指出,谢谢! 这次的题目一共有三个难度,分别是简单,中等偏下,中等。对于一些刚刚入门的小伙伴来说,比较友好。废话不多说,直接进入正题。...

python 队列基本定义与使用方法【初始化、赋值、判断等】

python 队列基本定义与使用方法【初始化、赋值、判断等】

本文实例讲述了python 队列基本定义与使用方法。分享给大家供大家参考,具体如下: 队列的特征是:先进先出 应用场景:消息通信、多进程间的协同、多线程间的协同等 在队列中需要设计的实例...

python在文本开头插入一行的实例

python在文本开头插入一行的实例

问题 对于一个文本文件,需要在起开头插入一行,其他内容不变 解决方法 with open('article.txt', 'r+') as f: content = f.read()...