python resize

import sys
import os
sys.path.append('/usr/local/lib/python2.7/site-packages')
sys.path.append('/usr/lib/python2.7/dist-packages')
import matplotlib.pyplot as plt
import cv2 def resizeimg(filename):
img=cv2.imread(filename)
shape=img.shape w=shape[1]
h=shape[0]
ww=w
hh=h
bresize=False
if w > h and w > 800:
ww=800
hh=h/(w/800)
bresize=True
if h > w and h > 800:
hh=800
ww=w/(h/800)
bresize=True
if bresize:
print filename
img=cv2.resize(img,(ww,hh))
cv2.imwrite(filename,img) for r, d, files in os.walk( '/var/Public/img/' ):
for ffile in files:
if ffile.endswith( 'jpg' ):
resizeimg(r+'/'+ffile)

  

上一篇:JS扩展方法——字符串trim()


下一篇:vmlinux,vmlinuz,bzimage,zimage,initrd.img的区别与联系