« [Extract]複数ページPDFを個別のファイルに分割【バッチ処理】 | トップページ | [kuler]TIFFANYの広告カラー【その2】 »

[PSDcs4]WEBおよびデバイス用に保存【少し直し】

こちら[LINK]新しいウィンドで開きますのスクリプトの少し直し版

やっぱりフォトショプの繰り返し処理等は
『バッチ』処理の方が
ファイルのオープン クローズが無いので
早い
ファイル名の処理も出来るので
AppleScriptsでチマチマやるより
アクション組んでバッチが基本だなぁ






on open DropObj

tell application "Adobe Photoshop CS4"
activate
end tell


tell application "Finder"
-----------------ファインダ アクティブ
activate
--------書き出し形式選択
set SetLabels to ¬
"[JPG quality60-120x]", ¬
"[JPG quality80-50]", ¬
"[JPG quality80]", ¬
"[JPGwMat]", ¬
"[PNG8]", ¬
"[PNG8wMat]", ¬
"[PNG24]", ¬
"[PNG24wMat]", ¬
"[PNG24trans]", ¬
"[GIF]", ¬
"[GIFwMat]", ¬
"[GIF128]"}
set SaveAns to choose from list SetLabels with prompt "フォーマットを選んでください" OK button name "実行する" with title "フォーマット選択"
set SaveForWebExportOptions to SaveAns as Unicode text



-----------------マットカラー指定
if (SaveForWebExportOptions is "[PNG8wMat]") then
--------RGB16bitColor16bitRGB値を格納
set the RGB16bitColor to (choose color default color {255, 255, 255})
--------RGB8bitColor8bitに変換した値を格納
set the R8bitColor to my RGB8bitR(RGB16bitColor)
set the G8bitColor to my RGB8bitG(RGB16bitColor)
set the B8bitColor to my RGB8bitB(RGB16bitColor)


else if (SaveForWebExportOptions is "[JPGwMat]") then
--------RGB16bitColor16bitRGB値を格納
set the RGB16bitColor to (choose color default color {255, 255, 255})
--------RGB8bitColor8bitに変換した値を格納
set the R8bitColor to my RGB8bitR(RGB16bitColor)
set the G8bitColor to my RGB8bitG(RGB16bitColor)
set the B8bitColor to my RGB8bitB(RGB16bitColor)

else if (SaveForWebExportOptions is "[PNG24wMat]") then
--------RGB16bitColor16bitRGB値を格納
set the RGB16bitColor to (choose color default color {255, 255, 255})
--------RGB8bitColor8bitに変換した値を格納
set the R8bitColor to my RGB8bitR(RGB16bitColor)
set the G8bitColor to my RGB8bitG(RGB16bitColor)
set the B8bitColor to my RGB8bitB(RGB16bitColor)

else if (SaveForWebExportOptions is "[GIFwMat]") then
--------RGB16bitColor16bitRGB値を格納
set the RGB16bitColor to (choose color default color {255, 255, 255})
--------RGB8bitColor8bitに変換した値を格納
set the R8bitColor to my RGB8bitR(RGB16bitColor)
set the G8bitColor to my RGB8bitG(RGB16bitColor)
set the B8bitColor to my RGB8bitB(RGB16bitColor)

end if




--------------------------------------------------変数リセット
set fileFcount to 0 ----カウントアップ用の数値
set fileFcountNo to "" as Unicode text ----ファイル名用のカウント数字の文字列
set NameSelect to "" as Unicode text ----リネームするか?オリジナルを保持するか?の判別用
set MainFileName to "" as Unicode text ----メインのファイル名
set exeName to "" as Unicode text
set newexeName to "" as Unicode text
--------------------------------------------------ファイル名を指定するか?を選ぶ リネーム か オリジナル保持か
display dialog "メインのファイル名はどうしますか?" default answer "img" buttons {"Rename", "Original"} with icon 1 default button 1
if button returned of the result is "Original" then
set resultFileName to text returned of the result as Unicode text
set the NameSelect to "2" as Unicode text
else if button returned of the result is "Rename" then
set resultFileName to text returned of the result as Unicode text
set the NameSelect to "1" as Unicode text
end if
--------------------------------------------------繰り返しの始まり
repeat with ObjFiles in DropObj

------------------------------------------------パスを取得
set pathAliasDoc to ObjFiles as alias

--------------------------------------------------ファイル名を取得
set fileName to name of ObjFiles as string

------------------------------------------------パスを文字列に変換
set pathStringDoc to pathAliasDoc as string

------------------------------------------------拡張子を判定
set exeName to name extension of ObjFiles

--------------------------------------------------もしもダイアログで Original を選んだら
if NameSelect is "2" then
--------------------------------------------------ファイル名から拡張子を取り除きそのままファイル名とする
set MainFileName to my replace(fileName, "." & exeName, "") as Unicode text
--------------------------------------------------もしもダイアログで Rename を選んだら
else if NameSelect is "1" then
--------------------------------------------------ダイアログをファイル名として連番を付加してファイル名を作る
set fileFcount to fileFcount + 1
set fileFcountNo to my zero2(fileFcount)
set the MainFileName to the fileFcountNo & "_" & resultFileName as Unicode text
end if
set the fileFcountNo to "" as Unicode text
-------------------------------------------------フルパスからファイル名を抜いてディレクトリ名を作る
set pathStringDirName to my replace(pathStringDoc, fileName, "") as string


--------------------------------------------------Photoshop呼び出し
tell application "Adobe Photoshop CS4"
--------------------------------------------------アクティブ
activate
--------------------------------------------------ファイルを開く
open alias pathStringDoc without dialogs
--------------------------------------------------開いたファイルをactivDocとして定義
set activDoc to document 1
--------------------------------------------------カラースペースをRGB
if (mode of activDoc is not RGB) then
change mode activDoc to RGB
end if
--------------------------------------------------チャンネルを8bit
if (bits per channel of activDoc is sixteen) then
set bits per channel of activDoc to eight
end if
--------------------------------------------------ドキュメントのサイズを取得 整数に丸める
------------注意!PSDの初期設定に単位が依存します。mmならmmサイズ pixelならピクセル値を返します。
set docHeight to height of activDoc as integer
set docWidth to width of activDoc as integer

--------------------------------------------------解像度94ppiへ変更(解像度は自分サイズって事ですので変更してください)
resize image activDoc resolution 94 width docWidth height docHeight resample method bicubic smoother



if (SaveForWebExportOptions is "[JPG quality80]") then

if NameSelect is "2" then
set the webFileName to the (MainFileName & "." & "jpg") as string
set savewebFileName to (pathStringDirName & ":" & webFileName)
else if NameSelect is "1" then
set the webFileName to the (the docWidth & "x" & docHeight & "_" & MainFileName & "." & "jpg") as string
set savewebFileName to (pathStringDirName & ":" & webFileName)
end if

export activDoc in file savewebFileName as save for web with options ¬
{class:save for web export options ¬
, blur:0 ¬
, interlaced:false ¬
, lossy:0 ¬
, optimized size:true ¬
, quality:80 ¬
, web format:JPEG ¬
, web snap:0 ¬
, with profile:false ¬
} ¬
with copying

close activDoc saving no

else if (SaveForWebExportOptions is "[JPG quality60-120x]") then


if docWidthdocHeight then
set wResio to (120 / docWidth)
set docWidth to (120) div 1 as integer
set docHeight to (docHeight * wResio) div 1 as integer

else if docWidth < docHeight then
set hResio to (120 / docHeight)
set docHeight to (120) div 1 as integer
set docWidth to (docWidth * hResio) div 1 as integer


end if

resize image activDoc resolution 94 width docWidth height docHeight resample method bicubic smoother

if NameSelect is "2" then
set the webFileName to the (MainFileName & "." & "jpg") as string
set savewebFileName to (pathStringDirName & ":" & webFileName)
else if NameSelect is "1" then
set the webFileName to the (the docWidth & "x" & docHeight & "_" & MainFileName & "." & "jpg") as string
set savewebFileName to (pathStringDirName & ":" & webFileName)
end if


export activDoc in file savewebFileName as save for web with options ¬
{class:save for web export options ¬
, blur:0 ¬
, interlaced:false ¬
, lossy:0 ¬
, optimized size:true ¬
, quality:60 ¬
, web format:JPEG ¬
, web snap:0 ¬
, with profile:false ¬
} ¬
with copying

close activDoc saving no



else if (SaveForWebExportOptions is "[JPG quality80-50]") then

set docWidth to (docWidth * 0.5) div 1 as integer
set docHeight to (docHeight * 0.5) div 1 as integer

resize image activDoc resolution 94 width docWidth height docHeight resample method bicubic smoother

if NameSelect is "2" then
set the webFileName to the (MainFileName & "." & "jpg") as string
set savewebFileName to (pathStringDirName & ":" & webFileName)
else if NameSelect is "1" then
set the webFileName to the (the docWidth & "x" & docHeight & "_" & MainFileName & "." & "jpg") as string
set savewebFileName to (pathStringDirName & ":" & webFileName)
end if


export activDoc in file savewebFileName as save for web with options ¬
{class:save for web export options ¬
, blur:0 ¬
, interlaced:false ¬
, lossy:0 ¬
, optimized size:true ¬
, quality:80 ¬
, web format:JPEG ¬
, web snap:0 ¬
, with profile:false ¬
} ¬
with copying

close activDoc saving no

else if (SaveForWebExportOptions is "[JPGwMat]") then

if NameSelect is "2" then
set the webFileName to the (MainFileName & "." & "jpg") as string
set savewebFileName to (pathStringDirName & ":" & webFileName)
else if NameSelect is "1" then
set the webFileName to the (the docWidth & "x" & docHeight & "_" & MainFileName & "." & "jpg") as string
set savewebFileName to (pathStringDirName & ":" & webFileName)
end if

export activDoc in file savewebFileName as save for web with options ¬
{class:save for web export options ¬
, blur:0 ¬
, interlaced:false ¬
, lossy:0 ¬
, optimized size:true ¬
, matte:({red:R8bitColor, green:G8bitColor, blue:B8bitColor}) ¬
, quality:80 ¬
, web format:JPEG ¬
, web snap:0 ¬
, with profile:false ¬
} ¬
with copying

close activDoc saving no




else if (SaveForWebExportOptions is "[PNG8]") then

if NameSelect is "2" then
set the webFileName to the (MainFileName & "." & "png") as string
set savewebFileName to (pathStringDirName & ":" & webFileName)
else if NameSelect is "1" then
set the webFileName to the (the docWidth & "x" & docHeight & "_" & MainFileName & "." & "png") as string
set savewebFileName to (pathStringDirName & ":" & webFileName)
end if

export activDoc in file savewebFileName as save for web with options ¬
{class:save for web export options ¬
, color reduction:adaptive ¬
, colors in palette:256 ¬
, dither:none ¬
, dither amount:100 ¬
, interlaced:false ¬
, png eight:true ¬
, transparency:true ¬
, transparency amount:100 ¬
, transparency dither:none ¬
, web format:PNG ¬
, web snap:0 ¬
} ¬
with copying
close document 1 saving no
else if (SaveForWebExportOptions is "[PNG8wMat]") then

if NameSelect is "2" then
set the webFileName to the (MainFileName & "." & "png") as string
set savewebFileName to (pathStringDirName & ":" & webFileName)
else if NameSelect is "1" then
set the webFileName to the (the docWidth & "x" & docHeight & "_" & MainFileName & "." & "png") as string
set savewebFileName to (pathStringDirName & ":" & webFileName)
end if

export activDoc in file savewebFileName as save for web with options ¬
{class:save for web export options ¬
, color reduction:adaptive ¬
, colors in palette:256 ¬
, dither:none ¬
, dither amount:100 ¬
, interlaced:false ¬
, matte:({red:R8bitColor, green:G8bitColor, blue:B8bitColor}) ¬
, png eight:true ¬
, transparency:true ¬
, transparency amount:100 ¬
, transparency dither:none ¬
, web format:PNG ¬
, web snap:0 ¬
} ¬
with copying
close document 1 saving no

else if (SaveForWebExportOptions is "[PNG24]") then
if NameSelect is "2" then
set the webFileName to the (MainFileName & "." & "png") as string
set savewebFileName to (pathStringDirName & ":" & webFileName)
else if NameSelect is "1" then
set the webFileName to the (the docWidth & "x" & docHeight & "_" & MainFileName & "." & "png") as string
set savewebFileName to (pathStringDirName & ":" & webFileName)
end if


export activDoc in file savewebFileName as save for web with options ¬
{class:save for web export options ¬
, interlaced:false ¬
, png eight:false ¬
, transparency:false ¬
, web format:PNG ¬
, web snap:0 ¬
} ¬
with copying

close document 1 saving no

else if (SaveForWebExportOptions is "[PNG24wMat]") then
if NameSelect is "2" then
set the webFileName to the (MainFileName & "." & "png") as string
set savewebFileName to (pathStringDirName & ":" & webFileName)
else if NameSelect is "1" then
set the webFileName to the (the docWidth & "x" & docHeight & "_" & MainFileName & "." & "png") as string
set savewebFileName to (pathStringDirName & ":" & webFileName)
end if


export document 1 in file savewebFileName as save for web with options ¬
{class:save for web export options ¬
, matte:{red:255, green:255, blue:255} ¬
, interlaced:false ¬
, png eight:false ¬
, transparency:true ¬
, web format:PNG ¬
, web snap:0 ¬
} ¬
with copying

close document 1 saving no


else if (SaveForWebExportOptions is "[PNG24trans]") then
if NameSelect is "2" then
set the webFileName to the (MainFileName & "." & "png") as string
set savewebFileName to (pathStringDirName & ":" & webFileName)
else if NameSelect is "1" then
set the webFileName to the (the docWidth & "x" & docHeight & "_" & MainFileName & "." & "png") as string
set savewebFileName to (pathStringDirName & ":" & webFileName)
end if

export document 1 in file savewebFileName as save for web with options ¬
{class:save for web export options ¬
, interlaced:false ¬
, png eight:false ¬
, transparency:true ¬
, web format:PNG ¬
, web snap:0 ¬
} ¬
with copying

close document 1 saving no


else if (SaveForWebExportOptions is "[GIFwMat]") then
if NameSelect is "2" then
set the webFileName to the (MainFileName & "." & "gif") as string
set savewebFileName to (pathStringDirName & ":" & webFileName)
else if NameSelect is "1" then
set the webFileName to the (the docWidth & "x" & docHeight & "_" & MainFileName & "." & "gif") as string
set savewebFileName to (pathStringDirName & ":" & webFileName)
end if

export activDoc in file savewebFileName as save for web with options ¬
{class:save for web export options ¬
, color reduction:perceptual reduction ¬
, colors in palette:256 ¬
, dither:none ¬
, dither amount:100 ¬
, interlaced:false ¬
, lossy:0 ¬
, quality:0 ¬
, matte:({red:R8bitColor, green:G8bitColor, blue:B8bitColor}) ¬
, transparency:true ¬
, transparency amount:100 ¬
, transparency dither:none ¬
, web format:CompuServe GIF ¬
, web snap:0 ¬
} ¬
with copying
close document 1 saving no
else if (SaveForWebExportOptions is "[GIF]") then
if NameSelect is "2" then
set the webFileName to the (MainFileName & "." & "gif") as string
set savewebFileName to (pathStringDirName & ":" & webFileName)
else if NameSelect is "1" then
set the webFileName to the (the docWidth & "x" & docHeight & "_" & MainFileName & "." & "gif") as string
set savewebFileName to (pathStringDirName & ":" & webFileName)
end if

export activDoc in file savewebFileName as save for web with options ¬
{class:save for web export options ¬
, color reduction:perceptual reduction ¬
, colors in palette:256 ¬
, dither:none ¬
, dither amount:100 ¬
, interlaced:false ¬
, lossy:0 ¬
, quality:0 ¬
, transparency:true ¬
, transparency amount:100 ¬
, transparency dither:none ¬
, web format:CompuServe GIF ¬
, web snap:0 ¬
} ¬
with copying
close document 1 saving no
else if (SaveForWebExportOptions is "[GIF128]") then
if NameSelect is "2" then
set the webFileName to the (MainFileName & "." & "gif") as string
set savewebFileName to (pathStringDirName & ":" & webFileName)
else if NameSelect is "1" then
set the webFileName to the (the docWidth & "x" & docHeight & "_" & MainFileName & "." & "gif") as string
set savewebFileName to (pathStringDirName & ":" & webFileName)
end if

export activDoc in file savewebFileName as save for web with options ¬
{class:save for web export options ¬
, color reduction:perceptual reduction ¬
, colors in palette:128 ¬
, dither:none ¬
, dither amount:100 ¬
, interlaced:false ¬
, lossy:0 ¬
, quality:0 ¬
, transparency:true ¬
, transparency amount:100 ¬
, transparency dither:none ¬
, web format:CompuServe GIF ¬
, web snap:0 ¬
} ¬
with copying
close document 1 saving no
end if
end tell
--------------------------------------------------にディレクトリ名とファイル名をつないでパスにしておく


--------------------------------------------------リセット
set docHeight to 0
set docWidth to 0
set exeName to "" as Unicode text
set newexeName to "" as Unicode text


end repeat
end tell
end open






--------------------------------------------------#ここからサブルーチン
to zero2(n)
if n < 10 then
return "00" & n
else if n < 100 then
return "0" & n
else
return n as text
end if
end zero2


to replace(theText, orgStr, newStr)
set oldDelim to AppleScript's text item delimiters
set AppleScript's text item delimiters to orgStr
set tmpList to every text item of theText
set AppleScript's text item delimiters to newStr
set tmpStr to tmpList as text
set AppleScript's text item delimiters to oldDelim
return tmpStr
end replace



------色のサブルーチン
on RGB8bitR({rColor, gColor, bColor})
set rColor to (rColor ^ 0.5) div 1
return rColor
end RGB8bitR

on RGB8bitG({rColor, gColor, bColor})
set gColor to (gColor ^ 0.5) div 1
return gColor
end RGB8bitG
on RGB8bitB({rColor, gColor, bColor})
set bColor to (bColor ^ 0.5) div 1
return bColor
end RGB8bitB


「save_for_web_v2.app.zip」をダウンロード[Download]新しいウィンドで開きます

|

« [Extract]複数ページPDFを個別のファイルに分割【バッチ処理】 | トップページ | [kuler]TIFFANYの広告カラー【その2】 »

AdobeAppleScript」カテゴリの記事

コメント

この記事へのコメントは終了しました。