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处理json字符串转化为字典的简单实现

今天一个朋友给个需求: 来来 {'isOK': 1, 'isRunning': None, 'isError': None} 怎么转换成字典 好,一看就是json转化很简单,开始:...

通过数据库对Django进行删除字段和删除模型的操作

删除字段 从Model中删除一个字段要比添加容易得多。 删除字段,仅仅只要以下几个步骤:     删除字段,然后重新启动你的web服务器。 &nb...

python使用正则搜索字符串或文件中的浮点数代码实例

用python和numpy处理数据次数比较多,写了几个小函数,可以方便地读写数据: # -*- coding: utf-8 -*- #------------------------...

Pandas_cum累积计算和rolling滚动计算的用法详解

Pandas主要统计特征函数: 方法名 函数功能 sum() 计算数据样本的总和(按列计...

对django中foreignkey的简单使用详解

公司里很多部门,每个部门可以发多条信息,但每条信息只对应一个部门 部门类: class Dep(models.Model): name = models.CharField('小...