python实现图片变亮或者变暗的方法

yipeiwu_com5年前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简单计算给定某一年的某一天是星期几示例

Python简单计算给定某一年的某一天是星期几示例

本文实例讲述了Python简单计算给定某一年的某一天是星期几。分享给大家供大家参考,具体如下: # -*- coding:utf-8 -*- #计算某特定天使星期几 #蔡勒公式:w=...

python实现简单聊天室功能 可以私聊

python实现简单聊天室功能 可以私聊

本文实例为大家分享了python实现简单聊天室功能的具体代码,供大家参考,具体内容如下 公共模块 首先写一个公共类,用字典的形式对数据的收发,并且进行封装,导入struct解决了TCP的...

用python + hadoop streaming 分布式编程(一) -- 原理介绍,样例程序与本地调试

用python + hadoop streaming 分布式编程(一) -- 原理介绍,样例程序与本地调试

MapReduce与HDFS简介 什么是Hadoop? Google为自己的业务需要提出了编程模型MapReduce和分布式文件系统Google File System,并发布了相关论文...

Matplotlib scatter绘制散点图的方法实现

Matplotlib scatter绘制散点图的方法实现

前言 考虑到很多同学可能还没有安装matplotlib包,这里给大家提供我常用的安装方法。首先Win键 + R,输入命令cmd打开命令行工具,再次在命令行工具中输入pip install...

wxPython实现窗口用图片做背景

wxPython实现窗口用图片做背景

本文实例为大家分享了wxPython实现窗口用图片做背景的具体代码,供大家参考,具体内容如下 效果图:   实现代码: #!/usr/bin/env python # -...