●Photoshopスクリプト2種 |
2012年4月 9日 |
Photoshopのちょっとしたスクリプトを2つ 1つ目はレイヤのタイプによってアクションを振り分けたい場合に使うアイデアです #target photoshop
activeLayerName = app.activeDocument.activeLayer.name;
//レイヤ名キーワードが含まれている場合に指定したアクションを実行
//1が含まれている場合
if (activeLayerName.indexOf("1") != -1){doAction("溶けた鉛","初期設定のアクション")}
//2が含まれている場合
else if (activeLayerName.indexOf("2") != -1){doAction("木製 (50 pixel)","初期設定のアクション")}
indexOf(" ")の" "の部分にキーワードを設定することで条件分岐内の処理させます ![]() このテキストを拡張子.jsxで保存してPhotoshopのファイル>スクリプト>参照 で開くことで実行できますし 『参照』で実行する操作をアクションに記録することもできます 他の使い方や他のスクリプト類はこちら を参照してください http://yukimi.moemoe.gr.jp/MT/archives/photoshop/ 2つ目は画像の拡大縮小に使えるアイデア
#target photoshop
//幅の初期値を設定
output_width = 1024
//ドキュメントの単位設定を保存
var strtRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits= Units.PIXELS;
var active_doc = app.activeDocument
var doc_width = active_doc.width
//リサイズ幅を指定
output_width = input_dialog(output_width)
//リサイズ処理
if (output_width){resize_with_frame(output_width)}
//ドキュメントの単位設定を戻す
app.preferences.rulerUnits = strtRulerUnits
//サイズ入力ダイアログ
function input_dialog(width)
{
dialog1 = new Window("dialog","幅を入力")
dialog1.bounds = [400,400,600,500]
dialog1.cancelButton = dialog1.add("button", [40,60,110,60+25], "Cancel", {name: "cancel"})
dialog1.okButton = dialog1.add("button",[120,60,170,60+25], "OK", { name:"ok"})
dialog1.sizetxt = dialog1.add("edittext",[10,10,110,10+25], width)
if (dialog1.show() == 1){
return dialog1.sizetxt.text
}
}
function resize_with_frame(output_width)
{
Trsp_to_mask()//透明度から選択範囲を作成
//選択範囲の拡大縮小で意図しない範囲を消去
active_doc.selection.expand(2)
active_doc.selection.contract (2)
active_doc.selection.invert()
//範囲を取得
selection_bound = active_doc.selection.bounds
selsction_width = selection_bound[2] - selection_bound[0]
//リサイズ
active_doc.resizeImage (output_width * doc_width / selsction_width)
}
//透明部分を選択範囲に
function Trsp_to_mask()
{
var id21 = charIDToTypeID( "setd" );
var desc4 = new ActionDescriptor();
var id22 = charIDToTypeID( "null" );
var ref2 = new ActionReference();
var id23 = charIDToTypeID( "Chnl" );
var id24 = charIDToTypeID( "fsel" );
ref2.putProperty( id23, id24 );
desc4.putReference( id22, ref2 );
var id25 = charIDToTypeID( "T " );
var ref3 = new ActionReference();
var id26 = charIDToTypeID( "Chnl" );
var id27 = charIDToTypeID( "Chnl" );
var id28 = charIDToTypeID( "Trsp" );
ref3.putEnumerated( id26, id27, id28 );
desc4.putReference( id25, ref3 );
executeAction( id21, desc4, DialogModes.NO );
}
枠のレイヤを選択した状態で枠の透明部分を基準が指定した幅になるように拡大縮小します
|


