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 控制语句

1比如python提倡简单实用的思想,它就没有switch语句,如果要实现switch语句的效果 的话可以通过2个方法来写把 (1)通过if elif 语句来实现 if 条件: … el...

python opencv 图像尺寸变换方法

利用Python OpenCV中的 cv.Resize(源,目标,变换方法)就可以实现变换为想要的尺寸了 源文件:就不用说了 目标:你可以对图像进行倍数的放大和缩小 也可以直接的输入尺寸...

你眼中的Python大牛 应该都有这份书单

你眼中的Python大牛 应该都有这份书单

在最新一期的话题中,80%读者认为Python是最好的编程语言,知乎上类似的问题也很多,例如如何入门Python?如何3个月内入门Python?虽然现在可以学习的Python途径...

Djang的model创建的字段和参数详解

class test_orm(models.Model): id = models.AutoField(primary_key=True) # int自增列,必须填入参数pr...

python中文分词,使用结巴分词对python进行分词(实例讲解)

python中文分词,使用结巴分词对python进行分词(实例讲解)

在采集美女站时,需要对关键词进行分词,最终采用的是python的结巴分词方法。 中文分词是中文文本处理的一个基础性工作,结巴分词利用进行中文分词。 其基本实现原理有三点: 1.基于Tri...