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实现多线程下载文件的代码实例

实现简单的多线程下载,需要关注如下几点:1.文件的大小:可以从reponse header中提取,如“Content-Length:911”表示大小是911字节2.任务拆分:指定各个线程...

Django框架使用内置方法实现登录功能详解

Django框架使用内置方法实现登录功能详解

本文实例讲述了Django框架使用内置方法实现登录功能。分享给大家供大家参考,具体如下: 一 内置登录退出思维导图 二 Django内置登录方法 1 位置...

解决vscode python print 输出窗口中文乱码的问题

一、搭建 python 环境 在 VSC 中点击 F1 键,弹出控制台,输入 ext install 界面左侧弹出扩展窗格,输入python,确认,开始搜索 下载发布者为Don Jaya...

python enumerate内置函数用法总结

python enumerate内置函数用法总结

这篇文章主要介绍了python enumerate内置函数用法总结,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 enumera...

python绘制铅球的运行轨迹代码分享

python绘制铅球的运行轨迹代码分享

我们按照面向过程程序设计的思想,使用python编写了程序,追踪铅球在运行过程中的位置信息。下面,修改程序代码,导入turtle模块,将铅球的运行轨迹绘制出来。 python3代码如下...