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

yipeiwu_com6年前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实现生成字符串大小写字母和数字的各种组合

1 输出大写字母、小写字母、大小写字母、数字、大小写字母和数字 1.1输出小写:找到小写a(97)到z(122)的的ASCII码,然后转义为字母 lower = "" for i i...

梯度下降法介绍及利用Python实现的方法示例

梯度下降法介绍及利用Python实现的方法示例

本文主要给大家介绍了梯度下降法及利用Python实现的相关内容,分享出来供大家参考学习,下面话不多说,来一起看看详细的介绍吧。 梯度下降法介绍 梯度下降法(gradient descen...

如何在sae中设置django,让sae的工作环境跟本地python环境一致

sae中安装有python环境,想让sae导入自己下载的django或者其他模块,可以在svn中新建一个文件目录,比如site-packages,跟python安装目录一样,这个目录存放...

python async with和async for的使用

网上async with和async for的中文资料比较少,我把PEP 492中的官方陈述翻译一下。 异步上下文管理器”async with” 异步上下文管理器指的是在enter和e...

Python使用PIL库实现验证码图片的方法

Python使用PIL库实现验证码图片的方法

本文实例讲述了Python使用PIL库实现验证码图片的方法。分享给大家供大家参考,具体如下: 现在的网页中,为了防止机器人提交表单,图片验证码是很常见的应对手段之一。这里就不详细介绍了,...