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

相关文章

用python3教你任意Html主内容提取功能

用python3教你任意Html主内容提取功能

本文将和大家分享一些从互联网上爬取语料的经验。 0x1 工具准备 工欲善其事必先利其器,爬取语料的根基便是基于python。 我们基于python3进行开发,主要使用以下几个模块:req...

python接口自动化测试之接口数据依赖的实现方法

在做自动化测试时,经常会对一整套业务流程进行一组接口上的测试,这时候接口之间经常会有数据依赖,那么具体要怎么实现这个依赖呢。 思路如下: 抽取之前接口的返回值存储到全局变量字典中...

Python实现求最大公约数及判断素数的方法

本文实例讲述了Python实现求最大公约数及判断素数的方法。分享给大家供大家参考。具体实现方法如下: #!/usr/bin/env python def showMaxFactor...

python实现名片管理器的示例代码

编写程序,完成“名片管理器”项目 需要完成的基本功能: 添加名片 删除名片 修改名片 查询名片 退出系统 程序运行后,除非选择退出系统,否则重复执行功能 mi...

Python解析json代码实例解析

这篇文章主要介绍了Python解析json代码实例解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 什么是json格式: JSON...