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

相关文章

解决Python3中的中文字符编码的问题

解决Python3中的中文字符编码的问题

python3中str默认为Unicode的编码格式 Unicode是一32位编码格式,不适合用来传输和存储,所以必须转换成utf-8,gbk等等 所以在Python3中必须将str类型...

python数字图像处理之高级滤波代码详解

python数字图像处理之高级滤波代码详解

本文提供许多的滤波方法,这些方法放在filters.rank子模块内。 这些方法需要用户自己设定滤波器的形状和大小,因此需要导入morphology模块来设定。 1、autolevel...

python修改list中所有元素类型的三种方法

修改list中所有元素类型: 方法一: new = list() a = ['1', '2', '3'] for x in a: new.append(int(x)) print(...

pandas对指定列进行填充的方法

实例如下所示: >>> import pandas as pd >>> import numpy as np >>> ts1 =...

如何用Python来理一理红楼梦里的那些关系

如何用Python来理一理红楼梦里的那些关系

前言 今天,一起用 Python 来理一理红楼梦里的那些关系 不要问我为啥是红楼梦,而不是水浒三国或西游,因为我也鉴定的认为,红楼才是无可争议的中国古典小说只巅峰,且不接受反驳!而红楼...