Python Notes #2 - 1.21.2013

来源:互联网 发布:matlab画二维数组 编辑:程序博客网 时间:2024/05/18 07:13

[图片来自Nathan Barry的Instagram, http://instagram.com/nathanbarry/]



图片的操作:

import mediapath = media.choose_file()pic = media.load_picture(path)media.show(pic)for p in media.get_pixels(pic):    new_blue = int(0.6 * media.get_blue(p))    new_green = int(0.6 * media.get_green(p))    media.set_blue(p, new_blue)    media.set_green(p, new_green)media.show(pic)print pic.titlenew_name = raw_input("Enter the name to save the new file:")new_name += '.jpg'media.save_as(pic, new_name)print pic.title

将图片的每个像素的蓝色和绿色降低为原来的60%,以便让图片看起来更暗,更红些。像是在暮光下拍的。


Python Shell:

[evaluate sunset.py]
C:/Python27/nearFlorence.jpg
Enter the name to save the new file:nearFlorenceSunset
nearFlorenceSunset.jpg