gikoha’s blog

個人的メモがわり

Photoshop script

PNG画像を並べる時に使うスクリプト (Photoshop CS Javascript)

アニメーションのため、3DCGソフトなどでいくつか画像を作っておき、横方向に並べたものを順次読み込むようにTexture2Dを改造しました。
ところが「画像を等間隔で並べる」のが異常に面倒くさいことが判明。
手作業ではやってられないので クリエイター手抜きプロジェクトを参考にしてscriptを作りました。

function multiCopy()
{
	folderObj = Folder.selectDialog("フォルダを選択してください");
	w = parseInt(prompt("枚数",3));
	h = 1;
	stepW = parseInt(prompt("1画像の幅",50));
	stepH = parseInt(prompt("1画像の縦",50));
	fileList = folderObj.getFiles("*.png");
	i = 0;
	var newDocumentRef = app.documents.add(stepW*w, stepH, 72.0, "newdoc");
	hh = stepW*(w-1)/2;
	for (x=0; x<w; x++)
	{
		fileObj = new File(fileList[i]);
		open(fileObj);
		activeDocument.selection.selectAll();
		activeDocument.selection.copy();
		activeDocument.close(SaveOptions.DONOTSAVECHANGES);
		newDocumentRef.paste();
		newDocumentRef.activeLayer.translate(x*stepW-hh,0);
		i++;
		if (i >= fileList.length) x=w;
	}
	newDocumentRef.artLayers[w].remove();	// 背景の削除
	for(x=1;x<w;x++)
	{
		newDocumentRef.activeLayer.merge();
	}
}
multiCopy()