접기
#target photoshop
app.bringToFront();
var boundaries = {x:100,y:75,width:300,height:300};
var docu = app.activeDocument;
var dlg = new Window("dialog", "다단계리사이즈 스크립트",boundaries);
dlg.inDataA = dlg.add("statictext", {x:50, y:20, width:200, height:20});
dlg.inDataB = dlg.add("statictext", {x:13, y:40, width:250, height:20});
dlg.inDataC = dlg.add("statictext", {x:28, y:60, width:250, height:20});
dlg.inDataD = dlg.add("statictext", {x:115, y:115, width:250, height:20});
dlg.inDataE = dlg.add("statictext", {x:115, y:160, width:250, height:20});
dlg.inData2 = dlg.add("statictext", {x:13, y:95, width:95, height:20}, "1. 리사이즈조절 :");
dlg.inData3 = dlg.add("edittext", {x:115, y:92, width:50, height:21}, "1800");
dlg.inData4 = dlg.add("statictext", {x:170, y:95, width:50, height:20}, "Pixcel");
dlg.inData4 = dlg.add("statictext", {x:13, y:140, width:95, height:20}, "2. 언샵마스크양 :");
dlg.inData4 = dlg.add("statictext", {x:115, y:140, width:30, height:20}, "양 =");
dlg.inData5 = dlg.add("edittext", {x:145, y:137, width:35, height:21}, "50");
dlg.inData6 = dlg.add("statictext", {x:185, y:140, width:45, height:20}, ", 반경 =");
dlg.inData7 = dlg.add("edittext", {x:233, y:137, width:25, height:21}, "1");
dlg.inData9 = dlg.add("statictext", {x:13, y:190, width:95, height:20}, "3. 원본파일위치 :");
dlg.inData10 = dlg.add("edittext", {x:115, y:188, width:170, height:21}, "4. 인화용");
dlg.inData11 = dlg.add("statictext", {x:13, y:215, width:95, height:20}, "4. 수정파일위치 :");
dlg.inData12 = dlg.add("edittext", {x:115, y:213, width:170, height:21}, "4. 인화용");
dlg.process = dlg.add("button", {x:70, y:260, width:80, height:25}, "적용");
dlg.cancel = dlg.add("button", {x:170, y:260, width:80, height:25}, "취소");
docRef = app.activeDocument;
dlg.inDataA.text = "■ 다단계 리사이즈를 위한 설정값 ■";
dlg.inDataB.text = "※ 4×3 인화시 최적의 해상도는 1800×1200";
dlg.inDataC.text = " 가로,세로 구분없이 장축을 기준으로 리사이즈";
dlg.inDataD.text = "(원본:" + docRef.width + " * " + docRef.height + ")";
dlg.inDataE.text = "(양:50~150 , 반경:0.5~1.0)";
dlg.center();
dlg.process.onClick = function() {
try {
var dlg = this.parent;
var rc = dlg.validate();
if (!rc) {
dlg.close();
}
} catch (e) {
alert(e);
}
}
dlg.cancel.onClick = function() {
//alert("다음 단계 액션실행에 문제가 발생합니다!");
dlg.close();
}
dlg.validate = function() {
if (!app.documents.length > 0) {
alert("열린 문서가 없습니다.");
}
else {
docRef = app.activeDocument;
var doc = app.activeDocument.duplicate();
var filePath = decodeURI(docRef.path);
var fileName = decodeURI(docRef.name);
var JPGfolder = new Folder(filePath + "/" + dlg.inData10.text);
JPGfolder.create();
var WEBfolder = new Folder(filePath + "/" + dlg.inData12.text);
WEBfolder.create();
app.displayDialogs = DialogModes.NO;
SaveFile = new File(filePath + "/" + dlg.inData10.text + "/" + fileName);
SaveJPEG(SaveFile,12);
fitImage(parseInt(dlg.inData3.text));
SaveFile = new File(filePath + "/" + dlg.inData12.text + "/" + "resize_" + fileName);
SaveJPEG(SaveFile,10);
doc.close(SaveOptions.DONOTSAVECHANGES);
alert("원본과 웹게시용 이미지가 " + dlg.inData10.text + " 폴더와 " + dlg.inData12.text + " 폴더에 각각 저장되었습니다!");
function fitImage(newImgSize) {
var docRef = app.activeDocument;
var prodImg = docRef.activeLayer;
var current_units = preferences.rulerUnits;
var ret = false;
var A = parseInt(dlg.inData5.text);
var B = parseInt(dlg.inData7.text);
var Alng = docRef.width;
var Bcnt = 0;
var Rads = 0;
if (docRef.width > docRef.height) {
while(ret==false && docRef.width > parseInt(dlg.inData3.text)){
Alng = (docRef.width - (docRef.width - Alng)) * 0.75
Bcnt = Bcnt + 1
ret = Alng <= parseInt(dlg.inData3.text)
}
if (Bcnt >= 6 && B <= 1) {
Rads = Rads + 0.1
} else
if (Bcnt == 5 && B <= 1) {
Rads = Rads + 0.2
} else
if (Bcnt <= 4 && B <= 1) {
Rads = Rads + 0.3
}
} else
if (docRef.width < docRef.height) {
while(ret==false && docRef.height > parseInt(dlg.inData3.text)){
Alng = (docRef.height - (docRef.height - Alng)) * 0.75
Bcnt = Bcnt + 1
ret = Alng <= parseInt(dlg.inData3.text)
}
if (Bcnt >= 6 && B <= 1) {
Rads = Rads + 0.1
} else
if (Bcnt == 5 && B <= 1) {
Rads = Rads + 0.2
} else
if (Bcnt <= 4 && B <= 1) {
Rads = Rads + 0.3
}
} else
if (docRef.width == docRef.height) {
while(ret==false && docRef.width > parseInt(dlg.inData3.text)){
Alng = (docRef.width - (docRef.width - Alng)) * 0.75
Bcnt = Bcnt + 1
ret = Alng <= parseInt(dlg.inData3.text)
}
if (Bcnt >= 6 && B <= 1) {
Rads = Rads + 0.1
} else
if (Bcnt == 5 && B <= 1) {
Rads = Rads + 0.2
} else
if (Bcnt <= 4 && B <= 1) {
Rads = Rads + 0.3
}
}
if (docRef.width > docRef.height) {
while(docRef.width * 0.75 > newImgSize){ //가로사진
preferences.rulerUnits = Units.PERCENT
docRef.resizeImage(75, undefined, undefined, ResampleMethod.BICUBICSHARPER)
prodImg.applyUnSharpMask(A,B,3);
if (B > 0.1) {
B = B - Rads
} else
if (B <= 0.1) {
B = 0.1
}
preferences.rulerUnits = Units.PIXELS;
}
preferences.rulerUnits = Units.PIXELS;
docRef.resizeImage(newImgSize, undefined, undefined, ResampleMethod.BICUBICSHARPER)
prodImg.applyUnSharpMask(300,0.1,3);
} else
if (docRef.width < docRef.height) {
while(docRef.height * 0.75 > newImgSize){ //세로사진
preferences.rulerUnits = Units.PERCENT
docRef.resizeImage(undefined, 75, undefined, ResampleMethod.BICUBICSHARPER)
prodImg.applyUnSharpMask(A,B,3);
if (B > 0.1) {
B = B - Rads
} else
if (B <= 0.1) {
B = 0.1
}
preferences.rulerUnits = Units.PIXELS;
}
preferences.rulerUnits = Units.PIXELS;
docRef.resizeImage(undefined, newImgSize, undefined, ResampleMethod.BICUBICSHARPER)
prodImg.applyUnSharpMask(300,0.1,3);
} else
if (docRef.width == docRef.height) {
while(docRef.height * 0.75 > newImgSize){ //정사각형
preferences.rulerUnits = Units.PERCENT
docRef.resizeImage(undefined, 75, undefined, ResampleMethod.BICUBICSHARPER)
prodImg.applyUnSharpMask(A,B,3);
if (B > 0.1) {
B = B - Rads
} else
if (B <= 0.1) {
B = 0.1
}
preferences.rulerUnits = Units.PIXELS;
}
preferences.rulerUnits = Units.PIXELS;
docRef.resizeImage(newImgSize, undefined, undefined, ResampleMethod.BICUBICSHARPER)
prodImg.applyUnSharpMask(300,0.1,3);
}
}
function SaveJPEG(saveFile, jpegQuality){
jpgSaveOptions = new JPEGSaveOptions()
jpgSaveOptions.embedColorProfile = true
jpgSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE
jpgSaveOptions.matte = MatteType.NONE
jpgSaveOptions.quality = jpegQuality //1-12
app.activeDocument.saveAs(saveFile, jpgSaveOptions, true,Extension.LOWERCASE)
}
}
}
dlg.show();
접기
- 포토샵의 자바스크립트 폴더에 저장한다.
- CS3의 경우 경로가 틀리므로 프로그램경로를 확인해서 넣어주면 된다.
- 포토샵을 실행하고 편집을 원하는 사진을 연다.
- 이러면 우선 SET 생성은 완료되었으며 액션탭에 폴더가 하나 생성된 것을 확인할 수 있다.
- 이제 아래와 같이 액션을 생성해보자. 동일한 방법으로
수정해서 쓰면 된다.