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中很多匹配,比如搜索任意位置的search()函数,搜索边界的match()函数,现在还需要学习一个全匹配函数,就是搜索的字符与...

Python比较配置文件的方法实例详解

工作中最常见的配置文件有四种:普通key=value的配置文件、Json格式的配置文件、HTML格式的配置文件以及YMAML配置文件。 这其中以第一种居多,后三种在成熟的开源产品中较为...

python查看FTP是否能连接成功的方法

本文实例讲述了python查看FTP是否能连接成功的方法。分享给大家供大家参考。具体如下: #!/usr/local/bin/python #-*- coding: UTF-8 -*...

解决PyCharm控制台输出乱码的问题

解决PyCharm控制台输出乱码的问题

最近公司新换了台电脑,各种开发环境要重新配置,想想Paas确实还是有市场的,如果有了,这种情况可以省下不少气力。吐槽一下,言归正传 装完python后,继续装好PyCharm。把之前的程...

python 通过logging写入日志到文件和控制台的实例

如下所示: import logging # 创建一个logger logger = logging.getLogger('mylogger') logger.setLev...