2015-03-02 112 views
0

更新: os.system提供了錯誤信息,這看起來很奇怪。爲什麼在圖像路徑之前沒有C:?絕對有文件夾中的文件。用python腳本中的imagemagick將tif文件轉換爲gif特定的命令

convert.exe: unable to open image `\\Users\\admin\\Desktop\\test\\1.tif',': No such file or directory @ error/blob.c/OpenBlob/2643. convert.exe: no decode delegate for this image format `\\Users\\admin\\Desktop\\ test\\1.tif',' @ error/constitute.c/ReadImage/555. convert.exe: unable to open image `\\Users\\admin\\Desktop\\test\\2.tif',': No such file or directory @ error/blob.c/OpenBlob/2643. convert.exe: no decode delegate for this image format `\\Users\\admin\\Desktop\\ test\\2.tif',' @ error/constitute.c/ReadImage/555. convert.exe: unable to open image `\\Users\\admin\\Desktop\\test\\3.tif']': No such file or directory @ error/blob.c/OpenBlob/2643. convert.exe: no decode delegate for this image format `\\Users\\admin\\Desktop\\ test\\3.tif']' @ error/constitute.c/ReadImage/555. convert.exe: no images defined `C:\Users\admin\Desktop\test\animated.gif' @ error/ convert.c/ConvertImageCommand/3147.

我想用ImageMagick的轉換TIF文件用下面python腳本吩咐GIF。但是,似乎是當我將圖像列表傳遞給imagemagick命令行字符串convert -alpha deactivate -verbose -delay 50 -loop 0 -density 300 {} {}animated.gif'.format(images, path)時,imagemagick無法識別圖像列表。

import os 

path = "C:\\Users\\admin\\Desktop\\test\\" 
filenames = ["2.tif", "1.tif", "3.tif"] 
images = [path + filename for filename in filenames] 
os.system('convert -alpha deactivate -verbose -delay 50 -loop 0 -density 300 {} {}animated.gif'.format(images, path)) 

通常情況下,我可以使用命令行convert -alpha deactivate -verbose -delay 50 -loop 0 -density 300 *.tif animated.gif'的東西轉換成當前文件夾中。但是就像這樣,我無法將tif文件順序指定爲我想要的。它會將文件轉換爲1.tif,2.tif,3.tif爲了最終的gif。

那麼有沒有辦法將python列表傳遞給imagemagick命令行字符串?

+0

@unutbu它給出了錯誤信息: – 2015-03-02 16:00:47

回答

0

我想回答我的問題。

一些挖後,我發現,ImageMagick的命令行可以接受像 convert -alpha deactivate -verbose -delay 50 -loop 0 -density 300 2.tif 1.tif 3.tif animated.gif'參數的話,就容易給人象下面這樣的解決方案:

import os 

path = "C:\\Users\\admin\\Desktop\\test\\" 
filenames = ["2.tif", "1.tif", "3.tif"] 
images = " ".join([path + filename for filename in filenames]) 
os.system('convert -alpha deactivate -verbose -delay 50 -loop 0 -density 300 {} {}animated.gif'.format(images, path)) 

使用連接功能的加入列表的字符串,把它傳遞給os.system,一切都會好的。

相關問題