python简单实现旋转图片的方法

yipeiwu_com5年前Python基础

本文实例讲述了python简单实现旋转图片的方法。分享给大家供大家参考。具体实现方法如下:

# rotate an image counter-clockwise using the PIL image library
# free from: http://www.pythonware.com/products/pil/index.htm
# make sure to install PIL after your regular python package is installed
import Image
# open an image file (.bmp,.jpg,.png,.gif)
# change image filename to something you have in the working folder
im1 = Image.open("Donald.gif")
# rotate 60 degrees counter-clockwise
im2 = im1.rotate(60)
# 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 an image viewer associated with this file type
im2.show()
# save the rotated image as d.gif to the working folder
# you can save in several different image formats, try d.jpg or d.png 
# PIL is pretty powerful stuff and figures it out from the extension
im2.save("d.gif")

希望本文所述对大家的Python程序设计有所帮助。

相关文章

对python中raw_input()和input()的用法详解

最近用到raw_input()和input()来实现即时输入,就顺便找了些资料来看,加上自己所用到的一些内容,整理如下: 1、raw_input() raw_input([promp...

Python 类的私有属性和私有方法实例分析

本文实例讲述了Python 类的私有属性和私有方法。分享给大家供大家参考,具体如下: xx:公有变量 _xx:公有变量或方法,不能通过import导入其他模块(只有模块内部使用)。类对象...

Python中字典的基础知识归纳小结

定义一个字典 >>> d = {"server":"mpilgrim", "database":"master"} 1 >>> d {'serve...

Python中列表、字典、元组数据结构的简单学习笔记

列表 列表是Python中最具灵活性的有序集合对象类型。与字符串不同的是,列表可以包含任何类型的对象:数字、字符串甚至其他列表。列表是可变对象,它支持原地修改的操作。 Python的列表...

Python使用scrapy采集数据时为每个请求随机分配user-agent的方法

本文实例讲述了Python使用scrapy采集数据时为每个请求随机分配user-agent的方法。分享给大家供大家参考。具体分析如下: 通过这个方法可以每次请求更换不同的user-age...