缩放图片文件,打印GPS信息到照片上
来源:互联网 发布:同城送餐软件 编辑:程序博客网 时间:2024/05/22 13:29
# -*- coding: cp936 -*-#WriteTo:yilong594@hotmail.comimport sysreload(sys)sys.setdefaultencoding('utf-8')import Image,ImageDrawimport osimport ImageFontif not os.path.exists('.\\resize'):os.mkdir('.\\resize')bakp="resize"def resizepic( pathname , bakpath , rate ): 'resize picture!' idx = pathname.rfind( '\\' ) filename = pathname[idx+1:len(pathname)] print filename fileurl = bakpath + '\\' + filename try: #打开原始图片 im = Image.open( pathname ) outim = im.resize( ( int(im.size[0]*rate), int(im.size[1]*rate ) )) outim.save( fileurl , "JPEG" ) except IOError: print 'Could not create new picture:' , pathname count = 0thefile = open('result.txt', 'rb')while True: buffer = thefile.read(8192*1024) if not buffer: break count += buffer.count('\n')thefile.close( )print countf=open('result.txt')row=[]for line in f.readlines(): columnline=line.split() column=[] for field in columnline: column.append(field) row.append(column)f.close()for b in range(0,count): resizepic(row[b][0],bakp,0.4) lastchar=u'°' try: float(row[b][2]) except: lastchar=u'' row[b][2]=row[b][2].replace('\'', u'\u2032') row[b][3]=row[b][3].replace('\'', u'\u2032') row[b][2]=row[b][2].replace('\"', u'\u2033') row[b][3]=row[b][3].replace('\"', u'\u2033') s1=u'\u7eac\u5ea6:' s2=u'\u7ecf\u5ea6:' s3=u'\u6d77\u62d4:' L1=s1+str(row[b][2])+lastchar L2=s2+str(row[b][3])+lastchar L3=s3+str(row[b][1])+'m' im=Image.open(bakp+"\\"+row[b][0]) fntsize=im.size[0]/20 fontlocate=(max(len(L1),len(L2),len(L3))-3)+3*2 fnt=ImageFont.truetype('simsun.ttc',fntsize) draw=ImageDraw.Draw(im) height1=10 height2=height1+fntsize height3=height1+fntsize*2 fntlc=im.size[0]-int(fntsize*fontlocate*0.53) draw.text((fntlc,height1),L1,font=fnt,fill='#ff0000') draw.text((fntlc,height2),L2,font=fnt,fill='#ff0000') draw.text((fntlc,height3),L3,font=fnt,fill='#ff0000') im.save(bakp+"\\"+os.path.splitext(row[b][0])[0]+'.jpg')