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中append实例用法总结

append()函数 描述:在列表ls最后(末尾)添加一个元素object 语法:ls.append(object) -> None 无返回值 例: a=[1,2,3] a....

python如何为被装饰的函数保留元数据

本文实例为大家分享了python为被装饰的函数保留元数据的具体代码,供大家参考,具体内容如下 案例:        在函数对...

在Python中过滤Windows文件名中的非法字符方法

网上有三种写法: 第一种(所有非法字符都不转义): def setFileTitle(self,title): fileName = re.sub('[\/:*&#...

python 正则式 概述及常用字符

1.元字符: . 它匹配除了换行字符外的任何字符,在 alternate 模式(re.DOTALL)下它甚至可以匹配换行 ^ 匹配行首。除非设置 MULTILINE 标志,它只是匹配字符...

通过实例浅析Python对比C语言的编程思想差异

通过实例浅析Python对比C语言的编程思想差异

我一直使用 Python,用它处理各种数据科学项目。 Python 以易用闻名。有编码经验者学习数天就能上手(或有效使用它)。 听起来很不错,不过,如果你既用 Python,同时也是用其...