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 leveldb

本文主要是对leveldb进行一个简单的介绍及使用Python语言对其进行操作的代码示例,具体如下。 leveldb 是google实现的一种非常高效的key-value数据库。key-...

django中静态文件配置static的方法

环境 centos7 django 1.11 nginx 白话 我们可以使用Template 设置我们的网页,同时,一个完美的网页需要css,js,image 等...

Python实现的归并排序算法示例

Python实现的归并排序算法示例

本文实例讲述了Python实现的归并排序算法。分享给大家供大家参考,具体如下: 归并排序是建立在归并操作上的一种有效的排序算法,该算法是采用分治法(Divide and Conquer)...

python实现数值积分的Simpson方法实例分析

本文实例讲述了python实现数值积分的Simpson方法。分享给大家供大家参考。具体如下: #coding = utf-8 #simpson 法计算积分,数值积分,效果非常理想 f...

利用python编写一个图片主色转换的脚本

利用python编写一个图片主色转换的脚本

前言 最近由于项目特需老是替换主题颜色,同时app里一些资源icon图片主色也要改,美工不提供切图只能靠自己了,开始想在iconfont上面找但是数量比较多太浪费时间,然后就想到pyth...