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程序设计有所帮助。

相关文章

把csv文件转化为数组及数组的切片方法

在Python中我们经常会用到两个库Numpy和pandas csv文件转化为数组 import numpy my_matrix = numpy.loadtxt(open("c:\\...

Python Numpy 自然数填充数组的实现

今天学习Numpy时,想到了一个小问题。在Numpy中,随机生成array是比较容易的,用np.random.rand即可。如下 a = np.random.rand(3,4) 可...

python实现数据导出到excel的示例--普通格式

此文是在django框架下编写,从数据库中获取数据使用的是django-orm 用python导出数据到excel,简单到爆!(普通的excel格式) 安装xlwt pip inst...

python SQLAlchemy的Mapping与Declarative详解

前面介绍过vSQLAlchemy中的 Engine 和 Connection,这两个对象用在row SQL (原生的sql语句)上操作,而 ORM(Object Relational M...

删除DataFrame中值全为NaN或者包含有NaN的列或行方法

如果存在以下DataFrame 年龄 性别 手机号 0 2 男 NaN 1 3 女 NaN 2 4...