python运行错误TypeError: unsupported operand type(s) for -: 'str' and 'str'
cut.py的内容如下:#-*-coding:utf-8-*-importImageimportsysimportos.pathfromdatetimeimport*im...
cut.py的内容如下:
# -*- coding: utf-8 -*- import Image import sys import os.path from datetime import * import random import time IMAGE_BAKUP = "/few" #_CONTENT_TYPES = { '.png': 'image/png', '.gif': 'image/gif', '.jpg': 'image/jpeg', '.jpeg': 'image/jpeg', '.jpe': 'image/jpeg' } _CONTENT_TYPES = { 'image/png': '.png', 'image/gif': '.gif', 'image/jpeg': '.jpg', 'image/jpeg': '.jpeg' } IMAGE_BAKUP = '' IMAGE_PATH = sys.argv[1] IMAGE_X1 = sys.argv[2] IMAGE_Y1 = sys.argv[3] IMAGE_X2 = sys.argv[4] IMAGE_Y2 = sys.argv[5] im = Image.open(IMAGE_PATH) #打开图片句柄 box = (IMAGE_X1,IMAGE_Y1,IMAGE_X2,IMAGE_Y2) #设定裁剪区域 region = im.crop(box) #裁剪图片,并获取句柄region region.save(IMAGE_BAKUP + datetime.now()+random.randint(0,99),) #保存图片 print int(time.time()); print '%s%s-%s%s'%(IMAGE_BAKUP,int(time.time()),random.randint(0,99), _CONTENT_TYPES[_CONTENT_TYPES])
运行后出错 展开
# -*- coding: utf-8 -*- import Image import sys import os.path from datetime import * import random import time IMAGE_BAKUP = "/few" #_CONTENT_TYPES = { '.png': 'image/png', '.gif': 'image/gif', '.jpg': 'image/jpeg', '.jpeg': 'image/jpeg', '.jpe': 'image/jpeg' } _CONTENT_TYPES = { 'image/png': '.png', 'image/gif': '.gif', 'image/jpeg': '.jpg', 'image/jpeg': '.jpeg' } IMAGE_BAKUP = '' IMAGE_PATH = sys.argv[1] IMAGE_X1 = sys.argv[2] IMAGE_Y1 = sys.argv[3] IMAGE_X2 = sys.argv[4] IMAGE_Y2 = sys.argv[5] im = Image.open(IMAGE_PATH) #打开图片句柄 box = (IMAGE_X1,IMAGE_Y1,IMAGE_X2,IMAGE_Y2) #设定裁剪区域 region = im.crop(box) #裁剪图片,并获取句柄region region.save(IMAGE_BAKUP + datetime.now()+random.randint(0,99),) #保存图片 print int(time.time()); print '%s%s-%s%s'%(IMAGE_BAKUP,int(time.time()),random.randint(0,99), _CONTENT_TYPES[_CONTENT_TYPES])
运行后出错 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询