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中在for循环中嵌套使用if和else语句的技巧

for...[if]...构建List (List comprehension) 1.简单的for...[if]...语句 Python中,for...[if]...语句一种简洁的构建L...

Python实现的序列化和反序列化二叉树算法示例

本文实例讲述了Python实现的序列化和反序列化二叉树算法。分享给大家供大家参考,具体如下: 题目描述 请实现两个函数,分别用来序列化和反序列化二叉树 序列化二叉树 先序遍历二叉树...

Python 实现取多维数组第n维的前几位

Python 实现取多维数组第n维的前几位

现在我们有一个shape为(7352, 9, 128, 1)的numpy数组。 想要取出第2维的前三个数据,构成新数组(7352, 3, 128, 1) 我的思想是:将第2维数据转置(t...

一文秒懂python读写csv xml json文件各种骚操作

Python优越的灵活性和易用性使其成为最受欢迎的编程语言之一,尤其是对数据科学家而言。 这在很大程度上是因为使用Python处理大型数据集是很简单的一件事情。 如今,每家科技公司都在制...

Python实现一个Git日志统计分析的小工具

前言 本文介绍的是利用Python实现的一个小工具,用于分析Git commit log,获得Git Project每个成员的简单行为数据。 Warning:代码量不能代表程序员能力水...