python Image模块学习
2016-05-16 22:31
513 查看
__author__ = 'fuquanjun' # -*- coding: utf-8 -*- from PIL import Image import ImageFont import ImageDraw import ImageFilter import sys import os class UImage(object): def __init__(self, path): self.im = Image.open(imagePath) (self.width, self.height) = self.im.size def getSize(self): return self.width, self.height def getHalfReduceImage(self, path, encoding= 'jpeg'): self.im.thumbnail((self.width//2, self.height//2)) self.im.save(path, encoding) def getReduceImageBySize(self, w, h, path, encoding= 'jpeg'): self.im.thumbnail((w, h)) self.im.save(path, encoding) def getReduceImageByRatio(self, w, h, path, encoding='jpeg'): self.im.thumbnail((self.width//w, self.height//h)) self.im.save(path,encoding) def getFuzzyImage(self,path): self.im = self.im.filter(ImageFilter.BLUR) self.im.save(path) def if __name__ == "__main__": #test get size imagePath = os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])), 'images') imagePath = os.path.join(imagePath, "1.jpg") uImage = UImage(imagePath) uImage.getHalfReduceImage(os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])), 'images')+'2.jpg') uImage.getReduceImageBySize(100, 100, os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])), 'images')+'3.jpg') uImage.getReduceImageByRatio(0.1, 0.1, os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])), 'images')+'4.jpg') uImage.getFuzzyImage(os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])), 'images')+'5.jpg')
相关文章推荐
- Python3写简单爬虫
- Python-----格式化字符
- leetcode(10),Roman to Integer(python)
- Python 格式化字符串
- Python点滴(五)-pandas进阶
- Windows下Eclipse+PyDev安装Python开发环境
- python中模拟进行ssh命令的执行
- python中模拟进行ssh命令的执行
- python
- python学习笔记4-python文件操作
- Python数据处理相关小例编程
- python的web问题
- python的web问题
- 打包Python程序为exe文件
- python用箱型图进行异常值检测
- py 4000 thon 时间差 datetime strptime
- python冒泡排序
- Python 线程学习
- Python 脚本注册为Windows Service
- Python WSGI