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编程中用close()方法关闭文件的教程

 close()方法方法关闭打开的文件。关闭的文件无法读取或写入更多东西。文件已被关闭之后任何操作会引发ValueError。但是调用close()多次是可以的。 Python...

Python编程中使用Pillow来处理图像的基础教程

安装 刚接触Pillow的朋友先来看一下Pillow的安装方法,在这里我们以Mac OS环境为例: (1)、使用 pip 安装 Python 库。pip 是 Python 的包管理工具,...

Python可变参数用法实例分析

Python可变参数用法实例分析

本文实例讲述了Python可变参数用法。分享给大家供大家参考,具体如下: #!/usr/bin/env python # -*- coding: utf-8 -*- import m...

一个基于flask的web应用诞生 bootstrap框架美化(3)

一个基于flask的web应用诞生 bootstrap框架美化(3)

经过上一章的内容,其实就页面层来说已结可以很轻松的实现功能了,但是很明显美观上还有很大的欠缺,现在有一些很好的前端css框架,如AmazeUI,腾讯的WeUI等等,这里推荐一个和flas...

python如何创建TCP服务端和客户端

本文实例为大家分享了python创建tcp服务端和客户端的具体代码,供大家参考,具体内容如下 1.服务端server from socket import * from time i...