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程序设计有所帮助。

相关文章

学习Django知识点分享

路由关系映射的一个小问题 URL中那个上尖号在正则中表示 以某某开头 $符号表示以某某结尾 这就限制了开头和结尾,也就固定了长度 但是 admin/123 也不能匹配到admin 为什...

Python读取Word(.docx)正文信息的方法

Python读取Word(.docx)正文信息的方法

本文介绍用Python简单读取*.docx文件信息,一些python-word库就是对这种方法的扩展。 介绍分两部分: Word(*.docx)文件简述 Python提取Wor...

python3中的eval和exec的区别与联系

看了很多网上的方法,写入文件后打开文件看确实不再是乱码,但是从文件中读入json时发现了乱码,可能是读文件默认的编码格式不对。下面读写方法可行。 注意,ensure_ascii=Fals...

详细探究Python中的字典容器

dictionary 我们都曾经使用过语言词典来查找不认识的单词的定义。语言词典针对给定的单词(比如 python)提供一组标准的信息。这种系统将定义和其他信息与实际的单词关联(映射)起...

基于Python实现的微信好友数据分析

基于Python实现的微信好友数据分析

最近微信迎来了一次重要的更新,允许用户对”发现”页面进行定制。不知道从什么时候开始,微信朋友圈变得越来越复杂,当越来越多的人选择”仅展示最近三天的朋友圈”,大概连微信官方都是一脸的无可奈...