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基础教程之分支、循环简单用法

本文实例讲述了python分支、循环简单用法。分享给大家供大家参考,具体如下: 讲程序设计,不得不讲到顺序、分支、循环。 顺序就是从上到下运行代码,这个很简单,不用再说了。 在讲分支、循...

Python记录详细调用堆栈日志的方法

本文实例讲述了Python记录详细调用堆栈日志的方法。分享给大家供大家参考。具体实现方法如下: import sys import os def detailtrace(info):...

Python 批量刷博客园访问量脚本过程解析

Python 批量刷博客园访问量脚本过程解析

今早无聊。。。7点起来突然想写个刷访问量的。。那就动手吧 仅供测试,不建议刷访问量哦~~ 很简单的思路,第一步提取代理ip,第二步模拟访问。 提取HTTP代理IP 网上很多收费的代理和...

在python tkinter中Canvas实现进度条显示的方法

在python tkinter中Canvas实现进度条显示的方法

如下所示: from tkinter import * import time #更新进度条函数 def change_schedule(now_schedule,all_sch...

代码讲解Python对Windows服务进行监控

我们首先来看下python的全部代码,大家可以直接复制后测试: #-*- encoding: utf-8 -*- import logging import wmi im...