#coding=utf-8
import Image
import urllib2
import StringIO
import os
#改变图片大小
def resize_img(img_path):
try:
img = Image.open(img_path)
(width,height) = img.size
new_width = 200
new_height = height * new_width / width
out = img.resize((new_width,new_height),Image.ANTIALIAS)
ext = os.path.splitext(img_path)[1]
new_file_name = '%s%s' %('small',ext)
out.save(new_file_name,quality=95)
except Exception,e:
print e
#改变图片类型
def change_img_type(img_path):
try:
img = Image.open(img_path)
img.save('new_type.png')
except Exception,e:
print e
#处理远程图片
def handle_remote_img(img_url):
try:
request = urllib2.Request(img_url)
img_data = urllib2