我正在研究Adobe After Effects的Extendscript工具,並試圖弄清楚一件事。 Extendscript只是Javascript的頂部添加了一些Adobe絨毛,但幾乎任何Javascript都不是特定於瀏覽器的作品。圖像序列的Javascript數組 - 僅返回序列中的第一個圖像
我有一段腳本我一直在使用/開發一段時間,這大大簡化了在圖像序列中導入數千幅圖像的過程。一切工作都很好,但有一個特定區域運行速度非常緩慢,當你開始進入數千張圖像時,我正試圖弄清楚如何加快速度。
我想要優化的是經過一系列可能有數千個圖像文件,並將其連接到序列中的第一個圖像。例如,我的數組可能是:[img.001.png,img.002.png,img.003.png,img.004.png,img.005.png],我想要做的是將每個「 img。###。png「除了第一個。所以在我的功能後,我只會:[img.001.png]。
以下是我現在就做:
1)我拿陣列項目A,正則表達式出來的數字序列
2)然後陣列B項,正則表達式出來的數字序列
3),並比較兩個以看看它們是否相同。如果他們是我拼接項目B
這適用於100%的時間真棒,但是當你獲得一千或兩個圖像以上時相當慢...我想要做的是找到一種方法更快地做到「修剪」步驟。我的一個朋友告訴我,正則表達式非常慢,所以也許我需要沒有正則表達式呢?我還發現了幾種原生JavaScript數組方法,它們可能有助於forEach()every()和filter(),但我不明白這些會如何更快,因爲我仍然需要做2次正則表達式評估,而且我仍然需要比較項目彼此。
任何幫助將非常感激!
- 斯賓塞
這裏是我現有的代碼片段:
currentFolder = new Folder ("//12.34.5.67/my folder on the network/")
var folderChildren = currentFolder.getFiles().sort();
var searcher = new RegExp("\\d{3,5}[.]");
for (var i = 0; i < folderChildren.length; i++) {
// Go through the array and strip out all elements that are the same once their numbers have been removed with a regex
if (i > 0) {
currentResult = searcher.exec(folderChildren[i].name); //check if a sequence
if (currentResult) { // it is a sequence
// first parse out the comparison strings - current item and item before
var testNameBefore = folderChildren[i-1].name;
//if we have a sequence before our current item, we need to delete the numbers.
var beforeNum = searcher.exec(testNameBefore);
if (beforeNum) {
testNameBefore = testNameBefore.substring(0, testNameBefore.length-8);
}
var testNameCurrent = folderChildren[i].name;
testNameCurrent = folderChildren[i].name.substring(0, testNameCurrent.length-8);
//compare to the element before it and delete if the same!!
if (testNameBefore == testNameCurrent) {
folderChildren.splice(i, 1);
i--;
}
}
}
}
是文件格式始終* .Number.png? – Jecoms
它總是以Number.png結尾,但並不總是在數字之前的一段時間。數字序列並不總是3位數字。 – Spencer