0

我们有一个包含大量图像及其视网膜图像的项目。是否有一种简单的方法或工具来检查每个图像是否有其相关的视网膜图像文件?我希望它是一个软件工具或一个简单的脚本,可以告诉我错过了哪个视网膜文件

欢迎任何评论

4

1 回答 1

1

你可以试试这个python脚本。请注意,它假定@2x 图像将与非视网膜版本位于同一目录中。如果您将视网膜图像和标准图像保存在不同的文件夹中,这将不起作用。它会按原样处理带有扩展名的文件.png.jpg但添加更多内容很容易。

这使用 *nixfind命令递归地获取当前工作目录中每个文件的路径。我是 python 新手,所以欢迎任何评论/修复/改进!

您可以手动运行它,也可以在 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
    test@2x.png
    test.png    

./more:
    cool_image.jpg
    john@2x.png
    file.png

./other:
    [empty]

运行(在终端中):

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

输出

./john.png
./more/cool_image.jpg
./more/file.png
于 2012-06-26T23:48:29.970 回答