用python寫了一個處理圖片的腳本,當然用到了另一個opensource的軟件ImageMagick-6.5.5-5.tar.gz,
安裝是三板斧 configure, make , make install
這裡用到的是python的一個系統調用subprocess.call
#! /usr/bin/env python
import sys, os, subprocess
fileSrc = open('./testClass2.txt','r')
aDict = dict() #創建一個dictionary
for line in fileSrc:
head, tail = line.split(',')
aDict[head]= tail #生成一個dictionary
fileSrc.close()
for atom in aDict:
if int(aDict[atom]) == 1:
srcStr=str('/home/demotest/source/yes/p9_%08d.jpg' % int(atom))
destStr=str('/home/demotest/source/yes/1/1_p9_%08d.jpg' % int(atom))
subprocess.call(['convert', srcStr, '-resize', '180x180', '-bordercolor', 'yellow', '-border', '10x10', destStr])
print '1----True'
elif int(aDict[atom]) == 9:
srcStr=str('/home/demotest/source/yes/p9_%08d.jpg' % int(atom))
destStr=str('/home/demotest/source/yes/9/9_p9_%08d.jpg' % int(atom))
subprocess.call(['convert', srcStr, '-resize', '580x580', '-bordercolor', 'yellow', '-border', '10x10', destStr])
print '9----True'
elif int(aDict[atom]) == 4:
srcStr=str('/home/demotest/source/yes/p9_%08d.jpg' % int(atom))
destStr=str('/home/demotest/source/yes/4/4_p9_%08d.jpg' % int(atom))
subprocess.call(['convert', srcStr, '-resize', '380x380', '-bordercolor', 'yellow', '-border', '10x10', destStr])
print '4----True'
else:
print 'no----True'
我這裡本來嘗試使用cmd.split()方式來,但是測試了半天沒有通過,放棄了,所以就用比較笨的辦法拼出來.
記錄一下! 繼續研究python
没有评论:
发表评论