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中字符串String的基本内置函数与过滤字符模块函数的基本用法

首先我们要明白在python中当字符编码为:UTF-8时,中文在字符串中的占位为3个字节,其余字符为一个字节 下面就直接介绍几种python中字符串常用的几种字符串内置函数(本文中牵扯到...

Python中按值来获取指定的键

Python字典中的键是唯一的,但不同的键可以对应同样的值,比如说uid,可以是1001。id同样可以是1001。这样的话通过值来获取指定的键,就不止一个!而且也并不太好处理。这里同样提...

介绍Python的Urllib库的一些高级用法

介绍Python的Urllib库的一些高级用法

1.设置Headers 有些网站不会同意程序直接用上面的方式进行访问,如果识别有问题,那么站点根本不会响应,所以为了完全模拟浏览器的工作,我们需要设置一些Headers 的属性。 首先,...

python3实现基于用户的协同过滤

本文实例为大家分享了python3实现基于用户协同过滤的具体代码,供大家参考,具体内容如下 废话不多说,直接看代码。 #!/usr/bin/python3 # -*- coding...

对python append 与浅拷贝的实例讲解

在做Leetcode的第39题的时候,看到网上一个用递归的解法,很简洁。于是重写了一遍。 class Solution(object): def combinationSum(se...