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

相关文章

对TensorFlow的assign赋值用法详解

TensorFlow修改变量值后,需要重新赋值,assign用起来有点小技巧,就是需要需要弄个操作子,运行一下。 下面这么用是不行的 import tensorflow as tf...

django框架cookie和session用法实例详解

django框架cookie和session用法实例详解

本文实例讲述了django框架cookie和session用法。分享给大家供大家参考,具体如下: 首先知道http协议 http协议它是无状态的协议,验证的信息不会保留 基于请求响应,短...

Python笔记(叁)继续学习

主题: 为什么要有方法呢? 回答居然是:懒惰是一种美德 方法的定义关键词:   def 用callable来判断是否是可调用: 复制代码 代码如下: x = 1 y = math.sqr...

基于python进行桶排序与基数排序的总结

本文首先举例阐述了两种排序方法的操作步骤,然后列出了用python进行的实现过程,最后对桶式排序方法的优劣进行了简单总结。 一、桶排序: 排序一个数组[5,3,6,1,2,7,5,10]...

cProfile Python性能分析工具使用详解

cProfile Python性能分析工具使用详解

前言 Python自带了几个性能分析的模块:profile、cProfile和hotshot,使用方法基本都差不多,无非模块是纯Python还是用C写的。本文介绍cProfile。 例子...