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
set the RGB16bitColor to (choose color default color {255, 255, 255})
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
set the RGB16bitColor to (choose color default color {255, 255, 255})
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
set the RGB16bitColor to (choose color default color {255, 255, 255})
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
set the RGB16bitColor to (choose color default color {255, 255, 255})
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
if NameSelect is "2" then
set MainFileName to my replace(fileName, "." & exeName, "") as Unicode text
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
tell application "Adobe Photoshop CS4"
activate
open alias pathStringDoc without dialogs
set activDoc to document 1
if (mode of activDoc is not RGB) then
change mode activDoc to RGB
end if
if (bits per channel of activDoc is sixteen) then
set bits per channel of activDoc to eight
end if
set docHeight to height of activDoc as integer
set docWidth to width of activDoc as integer
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 docWidth ≥ docHeight 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