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脚本在Nginx和uwsgi上部署MoinMoin的教程

在 CentOS 下使用 apache+mod_wsgi 部署了 MoinMoin,但是编辑和保存页面很慢,于是准备使用 nginx+uwsgi 重新部署 本文假定已经按照官方指引 Qu...

python实现决策树分类算法

python实现决策树分类算法

本文实例为大家分享了python实现决策树分类算法的具体代码,供大家参考,具体内容如下 1、概述 决策树(decision tree)——是一种被广泛使用的分类算法。 相比贝叶斯算法,决...

Python字符串的常见操作实例小结

本文实例讲述了Python字符串的常见操作。分享给大家供大家参考,具体如下: 如果我们想要查看以下功能:help(mystr .find) 1.find 例: mystr="hell...

django搭建项目配置环境和创建表过程详解

django搭建项目配置环境和创建表过程详解

1. 搭建项目配置环境和创建表 创建一个ttsx的项目 django-admin startproject ttsx 在ttsx下的__init__中导入mysql im...

Python读取excel指定列生成指定sql脚本的方法

需求 最近公司干活,收到一个需求,说是让手动将数据库查出来的信息复制粘贴到excel中,在用excel中写好的公式将指定的两列数据用update这样的语句替换掉。 例如: 有个A库,其...