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 pandas 对时间序列文件处理的实例

如下所示: import pandas as pd from numpy import * import matplotlib.pylab as plt import copy d...

使用Rasterio读取栅格数据的实例讲解

Rasterio简介 有没有觉得用GDAL的Python绑定书写的代码很不Pythonic,强迫症的你可能有些忍受不了。不过,没关系,MapBox旗下的开源库Rasterio帮我们解决了...

浅谈python和C语言混编的几种方式(推荐)

Python这些年风头一直很盛,占据了很多领域的位置,Web、大数据、人工智能、运维均有它的身影,甚至图形界面做的也很顺,乃至full-stack这个词语刚出来的时候,似乎就是为了描述它...

Python+Selenium+phantomjs实现网页模拟登录和截图功能(windows环境)

Python+Selenium+phantomjs实现网页模拟登录和截图功能(windows环境)

本文全部操作均在windows环境下 安装 Python Python是一种跨平台的计算机程序设计语言,它可以运行在Windows、Mac和各种Linux/Unix系统上。是一种面向对象...