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实现flappy bird游戏

flappy bird最近火遍大江南北,教你用python写游戏的第一课就向它开刀了。 这个课程的基础是假定你有比较不错的编程功底,对python有一点点的基础。 一、准备工作 1、用p...

linux下python抓屏实现方法

本文实例讲述了linux下python抓屏实现方法。分享给大家供大家参考。具体实现代码如下: #!/usr/bin/python '''by zevolo, 2012.12.20 '...

Pythony运维入门之Socket网络编程详解

Pythony运维入门之Socket网络编程详解

Socket是什么? Socket 是电脑网络中进程间数据流的端点Socket 是操作系统的通信机制应用程序通过Socket进行网络数据的传输 首先,简单了解一下TCP通信过程: TC...

python hook监听事件详解

python hook监听事件详解

本文实例为大家分享了python hook监听事件的具体代码,供大家参考,具体内容如下 # -*- coding: utf-8 -*- # # by oldj http://ol...

pandas.dataframe按行索引表达式选取方法

需要把一个从csv文件里读取来的数据集等距抽样分割,这里用到了列表表达式和dataframe.iloc 先生成索引列表: index_list = ['%d' %i for i in...