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

相关文章

pandas 如何分割字符的实现方法

pandas 如何分割字符的实现方法

摘要:本文主要是在pandas中如何对字符串进行切分。我们考虑一下下面的应用场景。 这个是我们的数据集(data),可以看到,数据集中某一列(name)是某个行业的分类。各个行业之间...

python+mysql实现简单的web程序

这次要为我的python程序加上数据库,主要是实现从mysql中查询出数据并在页面上显示出来。 首先是mysql的配置文件config.py host="127.0.0.1" use...

python 搭建简单的http server,可直接post文件的实例

server: #coding=utf-8 from BaseHTTPServer import BaseHTTPRequestHandler import cgi class Po...

解决Tensorflow使用pip安装后没有model目录的问题

解决Tensorflow使用pip安装后没有model目录的问题

在使用pip安装Tensorflow后,在其目录中没有找到model目录,重复安装了两遍依然没有,原因未知。 于是,使用源码安装的方法: (1)收下,使用git clone源码工程: g...

分析python切片原理和方法

分析python切片原理和方法

使用索引获取列表的元素(随机读取) 列表元素支持用索引访问,正向索引从0开始 colors=["red","blue","green"] colors[0] =="red"...