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

相关文章

详解pandas的外部数据导入与常用方法

外部数据导入 导入excel文件 pandas导入excel用read_excel()方法: import pandas as pd excel_file1 = pd.read_...

python3 property装饰器实现原理与用法示例

本文实例讲述了python3 property装饰器实现原理与用法。分享给大家供大家参考,具体如下: 学习python的同学,慢慢的都会接触到装饰器,装饰器在python里是功能强大的语...

python字符串替换第一个字符串的方法

Python 截取字符串使用 变量[头下标:尾下标],就可以截取相应的字符串,其中下标是从0开始算起,可以是正数或负数,下标可以为空表示取到头或尾。 # 例1:字符串截取 str...

对pandas数据判断是否为NaN值的方法详解

实际项目中有这样的需求,将某一列的值,映射成类别型的数据,这个时候,需要我们将范围等频切分,或者等距切分。 具体的做法可以先看某一些特征的具体分布情况,然后我们选择合适的阈值进行分割。...

python查看文件大小和文件夹内容的方法

一旦有办法处理文件路径,就可以开始搜集特定文件和文件夹的信息。os.path 模块提供了一些函数,用于查看文件的字节数以及给定文件夹中的文件和子文件夹。 • 调用 os.pa...