0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Photoshop Script(JSX)を使ってレイヤーごとに保存する

Last updated at Posted at 2021-01-25

##はじめに
普段photoshopを使用している中で「レイヤーごとに書き出し」が不便だと思ったので、勉強がてらPhotoshop Scriptを書いてみました。
既存の素晴らしいものがあるとは思いますが、個人的に必要最低限のシンプルなものがほしかったので簡潔なものになってます。
備忘録的位置づけで簡単な説明を添えてこちらにおいておきます。

##機能&操作
・常に表示させたいレイヤーはロックしておく(背景や上に乗せるロゴなど共通のもの)
・ロックされているレイヤーは無視して、順番にレイヤーを書き出していく

##コード全文


const saveFolderPath = Folder.selectDialog("フォルダを選択してください");

function divideVisibleBylocked(){
    for (i=0; i < activeDocument.layers.length; i++){
        var activeLayer = activeDocument.layers[i]
        if(activeLayer.allLocked == true){
            activeLayer.visible = true;
        }else{
            activeLayer.visible = false;
        }
    }
}

function allLayerSave(){
    for (i=0; i < activeDocument.layers.length; i++){
        var activeLayer = activeDocument.layers[i]
        if(activeLayer.allLocked == false){
            var layerName = activeLayer.name;
            var fileName = layerName + ".jpg";
            var filePath = saveFolderPath+ "/" + fileName;
            activeLayer.visible = true;
            saveJpegImage(filePath);
            activeLayer.visible = false;
        }
    }
}

divideVisibleBylocked()
allLayerSave()


// --------------------------------------------
function saveJpegImage(filePath){
    fileObj = new File(filePath);
    jpegOpt = new JPEGSaveOptions();
    jpegOpt.embedColorProfile = true;
    jpegOpt.quality = 12;
    jpegOpt.formatOptions = FormatOptions.PROGRESSIVE;
    jpegOpt.scans = 3;
    jpegOpt.matte = MatteType.NONE;
    activeDocument.saveAs(fileObj, jpegOpt, true, Extension.LOWERCASE);
}

###保存先指定

const saveFolderPath = Folder.selectDialog("フォルダを選択してください");

###ロックされているレイヤーはすべて表示、されてないレイヤーはすべて非表示に

function divideVisibleBylocked(){
    for (i=0; i < activeDocument.layers.length; i++){
        var activeLayer = activeDocument.layers[i]
        if(activeLayer.allLocked == true){
            activeLayer.visible = true;
        }else{
            activeLayer.visible = false;
        }
    }
}

###ロックされているレイヤ以外を1つずつ表示して書き出し

function allLayerSave(){
    for (i=0; i < activeDocument.layers.length; i++){
        var activeLayer = activeDocument.layers[i]
        if(activeLayer.allLocked == false){
            var layerName = activeLayer.name;
            var fileName = layerName + ".jpg";
            var filePath = saveFolderPath+ "/" + fileName;
            activeLayer.visible = true;
            saveJpegImage(filePath);
            activeLayer.visible = false;
        }
    }
}

###jpgでの書き出し

function saveJpegImage(filePath){
    fileObj = new File(filePath);
    jpegOpt = new JPEGSaveOptions();
    jpegOpt.embedColorProfile = true;
    jpegOpt.quality = 12;
    jpegOpt.formatOptions = FormatOptions.PROGRESSIVE;
    jpegOpt.scans = 3;
    jpegOpt.matte = MatteType.NONE;
    activeDocument.saveAs(fileObj, jpegOpt, true, Extension.LOWERCASE);
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?