PHP-Code:
function main() {
var filterAr = new Array ('tif','jpg','psd','png','gif');
var source=new Folder (dlg.pan_folder.txt_qellpfad.text);
var target=new Folder (dlg.pan_folder.txt_zielpfad.text);
var allFiles=source.getFiles();
getImages(source,allFiles.length);
for (var i=0; i<imageFiles.length;i++) {
dlg.info2.text="laden...";
dlg.info.text="Bild "+(i+1)+"/"+ imageFiles.length;
var docref=app.open(imageFiles[i]);
dlg.info2.text="resize...";
resizeDoc (docref,dlg.pan_opt.txt_breite.text*1,dlg.pan_opt.txt_hoehe.text*1);
dlg.info2.text="speichern...";
if (dlg.pan_opt.pan_save.rb_psd.value==true) {
save_PSD(docref);
} else {
save_JPG(docref);
}
docref.close(SaveOptions.DONOTSAVECHANGES);
}
dlg.info2.text="Fertig!";
}
function getImages(SFolder,l) {
var filterAr = new Array ('tif','jpg','psd','png','gif');
var TFiles= SFolder.getFiles();
for (var i = 0; i < TFiles.length; i++) {
if (TFiles[i] instanceof Folder) {
TFolder=dlg.pan_folder.txt_zielpfad.text+TFiles[i].fullName.replace(dlg.pan_folder.txt_qellpfad.text,"");
Folder(TFolder).create();
getImages(TFiles[i],TFiles.length);
}
var dotPos = TFiles[i].name.lastIndexOf( "." );
if (dotPos < 1) continue;
var process = false;
fExtLc = TFiles[i].name.substring(dotPos+1).toLowerCase();
for (var y = 0; y < filterAr.length; y++)
{
process =(filterAr[y] == fExtLc);
if (process == true) break;
}
if (process == false) continue;
imageFiles.push(TFiles[i]);
}
}
function resizeDoc(doc,toX,toY) {
// nur verkleinern
if (dlg.pan_opt.rb_small.value==true) {
if (doc.width>toX || doc.height>toY) {
if (doc.width/toX > doc.height/toY) {
doc.resizeImage(toX,undefined, undefined, ResampleMethod.BICUBIC);
} else {
doc.resizeImage(undefined,toY, undefined, ResampleMethod.BICUBIC);
}
}
}
// nur vergrössern
if (dlg.pan_opt.rb_big.value==true) {
if (doc.width<toX || doc.height<toY) {
if (doc.width/toX > doc.height/toY) {
doc.resizeImage(toX,undefined, undefined, ResampleMethod.BICUBIC);
} else {
doc.resizeImage(undefined,toY, undefined, ResampleMethod.BICUBIC);
}
}
}
// beides
if (dlg.pan_opt.rb_both.value==true) {
if (doc.width/toX > doc.height/toY) {
doc.resizeImage(toX,undefined, undefined, ResampleMethod.BICUBIC);
} else {
doc.resizeImage(undefined,toY, undefined, ResampleMethod.BICUBIC);
}
}
}
function save_JPG(doc) {
if(doc.mode != "RGB") doc.changeMode(ChangeMode.RGB);
saveOptions = new JPEGSaveOptions();
saveOptions.embedColorProfile = true;
saveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
saveOptions.matte = MatteType.NONE;
saveOptions.quality = dlg.pan_opt.pan_save.txt_qualitaet.text;
doc.flatten();
var saveFile=doc.fullName.toString();
saveFile=new File (saveFile.replace(dlg.pan_folder.txt_qellpfad.text,dlg.pan_folder.txt_zielpfad.text));
doc.saveAs(saveFile,saveOptions,false, Extension.LOWERCASE);
}
function save_PSD(doc) {
if(doc.mode != "RGB") doc.changeMode(ChangeMode.RGB);
psdSaveOptions = new PhotoshopSaveOptions();
psdSaveOptions.embedColorProfile = true;
psdSaveOptions.alphaChannels = true;
saveFile=new File (saveFile.replace(dlg.pan_folder.txt_qellpfad.text,dlg.pan_folder.txt_zielpfad.text));
doc.saveAs(saveFile, psdSaveOptions, true, Extension.LOWERCASE);
}
//Variablen
var strtRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
var imageFiles = new Array;
var inputFolder;
var outputFolder;
//GUI
var res="dialog{text:'Resize by hotschen',bounds:[100,100,460,370],\
pan_folder:Panel{bounds:[10,10,350,95] , text:'Ordnerauswahl ' ,properties:{borderStyle:'etched',su1PanelCoordinates:true},\
statictext0:StaticText{bounds:[10,22,70,39] , text:'Quellpfad:' ,properties:{scrolling:undefined,multiline:false}},\
statictext1:StaticText{bounds:[10,52,60,69] , text:'Zielpfad:' ,properties:{scrolling:undefined,multiline:false}},\
txt_qellpfad:EditText{bounds:[70,20,290,40] , text:'' ,properties:{multiline:false,noecho:false,readonly:false}},\
btn_quellpfad:Button{bounds:[300,20,330,40] , text:'...' },\
btn_zielpfad:Button{bounds:[300,50,330,70] , text:'...' },\
txt_zielpfad:EditText{bounds:[70,50,290,70] , text:'' ,properties:{multiline:false,noecho:false,readonly:false}}\
},\
pan_opt:Panel{bounds:[10,110,350,230] , text:'Einstellungen ' ,properties:{borderStyle:'etched',su1PanelCoordinates:true},\
rb_small:RadioButton{bounds:[10,50,111,71] , text:'Nur verkleinern',value:true },\
rb_big:RadioButton{bounds:[10,70,111,91] , text:'Nur vergrössern' },\
rb_both:RadioButton{bounds:[10,90,190,111] , text:'Vergrössern und verkleinern' },\
statictext3:StaticText{bounds:[10,22,70,42] , text:'Zielgrösse:' ,properties:{scrolling:undefined,multiline:false}},\
txt_breite:EditText{bounds:[70,20,110,40] , text:'800' ,properties:{multiline:false,noecho:false,readonly:false}},\
statictext4:StaticText{bounds:[111,22,121,39] , text:'x' ,properties:{scrolling:undefined,multiline:false}},\
txt_hoehe:EditText{bounds:[120,20,160,40] , text:'600' ,properties:{multiline:false,noecho:false,readonly:false}},\
statictext5:StaticText{bounds:[160,20,180,37] , text:'px' ,properties:{scrolling:undefined,multiline:false}},\
pan_save:Panel{bounds:[200,10,330,111] , text:'Speicheroptionen' ,properties:{borderStyle:'etched',su1PanelCoordinates:true},\
rb_psd:RadioButton{bounds:[20,20,121,41] , text:'PSD', value:true },\
rb_jpg:RadioButton{bounds:[20,40,121,61] , text:'JPG' },\
slider:Slider{bounds:[20,80,121,90] , minvalue:1,maxvalue:12,value:10,visible:false},\
statictext9:StaticText{bounds:[20,62,70,79] , text:'Qualität' ,visible:false,properties:{scrolling:undefined,multiline:false}},\
txt_qualitaet:EditText{bounds:[80,60,110,80] , text:'10' ,visible:false,properties:{multiline:false,noecho:false,readonly:false}}\
}\
},\
info:StaticText{bounds:[20,232,120,250] , text:'' ,properties:{scrolling:undefined,multiline:false}},\
info2:StaticText{bounds:[20,252,120,270] , text:'' ,properties:{scrolling:undefined,multiline:false}},\
btn_ok:Button{bounds:[130,240,230,260] , text:'Los gehts' },\
btn_cancel:Button{bounds:[250,240,350,260] , text:'Abbrechen' }\
};"
//GUI-Funktionen
var dlg=new Window (res);
dlg.btn_ok.onClick=function() {
main();
};
dlg.btn_cancel.onClick =function () {
app.preferences.rulerUnits = strtRulerUnits;
this.parent.close(2);
};
dlg.pan_folder.btn_quellpfad.onClick=function() {
inputFolder= Folder.selectDialog("Quellverzeichnis auswählen");
dlg.pan_folder.txt_qellpfad.text = inputFolder.toString()+"/";
};
dlg.pan_folder.btn_zielpfad.onClick=function() {
outputFolder= Folder.selectDialog("Zielverzeichnis auswählen").toString();
dlg.pan_folder.txt_zielpfad.text = outputFolder.toString()+"/";
};
dlg.pan_opt.pan_save.slider.onChange=function() {
dlg.pan_opt.pan_save.txt_qualitaet.text=this.value;
}
dlg.pan_opt.pan_save.rb_jpg.onClick=function() {
dlg.pan_opt.pan_save.txt_qualitaet.visible=this.value;
dlg.pan_opt.pan_save.slider.visible=this.value;
dlg.pan_opt.pan_save.statictext9.visible=this.value;
}
dlg.pan_opt.pan_save.rb_psd.onClick=function() {
dlg.pan_opt.pan_save.txt_qualitaet.visible=!this.value;
dlg.pan_opt.pan_save.slider.visible=!this.value;
dlg.pan_opt.pan_save.statictext9.visible=!this.value;
}
dlg.center();
dlg.show();