Home > Backend Development > Python Tutorial > python判断图片宽度和高度后删除图片的方法

python判断图片宽度和高度后删除图片的方法

WBOY
Release: 2016-06-10 15:11:56
Original
1141 people have browsed it

本文实例讲述了python判断图片宽度和高度后删除图片的方法。分享给大家供大家参考。具体分析如下:

Image对象有open方法却没有close方法,如果打开图片,判断图片高度和宽度,判断完成后希望删除或者给图片改名,是无法操作的,这段代码可以解决这个问题,注意open函数打开图片文件要使用二进制方式,及参数使用'rb',有的文章给出的只有个'r'参数,Image是无法open的

import os
import Image
fileName = 'c:/py/jb51.jpg'
fp = open(fileName,'rb')
im = Image.open(fp)
fp.close()
x,y = im.size
if x <300 or y < 300:
   os.remove(fileName)

Copy after login

希望本文所述对大家的Python程序设计有所帮助。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template