2012-06-26 26 views
0

我們有一個項目,有很多圖像和他們的視網膜圖像。 有沒有簡單的方法或工具來檢查每個圖像是否有其相關的視網膜圖像文件? 我希望這將是一個軟件工具或一個簡單的腳本,可以告訴我哪視網膜文件遺漏檢查視網膜圖像文件丟失

歡迎任何評論

+2

你見過這樣的:HTTP:// www.splinter.com.au/quickly-check-for-any-missing-retina-graphics/? –

回答

1

你可以試試這個python腳本。請注意,它假定@ 2x圖像與非視網膜版本位於同一目錄中。如果您將視網膜和標準圖像保存在不同的文件夾中,這將不起作用。它將按原樣處理.png.jpg擴展名的文件,但添加更多內容很容易。

這使用* nix find命令以遞歸方式獲取當前工作目錄中每個文件的路徑。我是一個蟒蛇新手,所以任何意見/修復/改進是值得歡迎的!

你可以手動運行,或者你可以在xcode的預編譯鉤子中使用它。它返回沒有@ 2x版本的文件的路徑。

from subprocess import check_output 
from os import path 
import string 

# Get all the files in the current working dir, recursively 
files_raw = check_output(["find","-type","f"]) 
paths = files_raw.split("\n") 

# Remove the empty last element (find command ends with a newline) 
paths.pop() 

for item in paths: 
    # Ignore any @2x items 
    if("@2x" in item): 
     continue 

    # Break up the path 
    filename, extension = path.splitext(item) 

    # Ignore files without these extensions 
    if(extension not in [".png", ".jpg"]): 
     continue 

    # Make the rentina path and see if it's in the list of paths 
    retina = filename+"@2x"+extension 
    if(retina not in paths): 
     print item 

例如,對於這個文件夾:

.: 
    file.txt 
    john.png 
    [email protected] 
    test.png  

./more: 
    cool_image.jpg 
    [email protected] 
    file.png 

./other: 
    [empty] 

運行(在終端):

cd /home/stecman/test-dir 
python /home/stecman/missing-retina.py 

輸出

./john.png 
./more/cool_image.jpg 
./more/file.png 
+0

對於其他人檢查這個答案,我認爲這個問題的第一個評論的鏈接是比這個更好的答案(參見http://www.splinter.com.au/quickly-check-for-any-missing -retina圖形/)。爲什麼? 1 /它不介意圖像的文件系統位置2 /它檢查圖像實際上是iOS目標的一部分。 –