/* ------CS6102 Graphics and Graphic Design------
------------Yang Yang - 110220265----------- */
app.preferences.rulerUnits = Units.PIXELS;
//------Select Background Image------//
var bgImg = File.openDialog("Please Select Background Photo","*.*");
app.load(bgImg);
var bgPhoto = app.documents[0];
//------Create A Dialog Window as UI------//
var dig = new Window('dialog', 'Poster Interface - Chose 5 Images', [100,200,600,580]);
dig.panel1 = dig.add('panel', [10,10,480,70], 'Image 1');
dig.panel2 = dig.add('panel', [10,70,480,130], 'Image 2');
dig.panel3 = dig.add('panel', [10,130,480,190], 'Image 3');
dig.panel4 = dig.add('panel', [10,190,480,250], 'Image 4');
dig.panel5 = dig.add('panel', [10,250,480,310], 'Image 5');
dig.panel1.label = dig.panel1.add('statictext' , [20,20,130,40],'Choose Image1:');
dig.panel2.label = dig.panel2.add('statictext' , [20,20,130,40],'Choose Image2:');
dig.panel3.label = dig.panel3.add('statictext' , [20,20,130,40],'Choose Image3:');
dig.panel4.label = dig.panel4.add('statictext' , [20,20,130,40],'Choose Image4:');
dig.panel5.label = dig.panel5.add('statictext' , [20,20,130,40],'Choose Image5:');
dig.panel1.t = dig.panel1.add('edittext', [140,20,370,40]);
dig.panel2.t = dig.panel2.add('edittext', [140,20,370,40]);
dig.panel3.t = dig.panel3.add('edittext', [140,20,370,40]);
dig.panel4.t = dig.panel4.add('edittext', [140,20,370,40]);
dig.panel5.t = dig.panel5.add('edittext', [140,20,370,40]);
dig.panel1.bt = dig.panel1.add('button', [390,20,450,40], 'Browse');
dig.panel2.bt = dig.panel2.add('button', [390,20,450,40], 'Browse');
dig.panel3.bt = dig.panel3.add('button', [390,20,450,40], 'Browse');
dig.panel4.bt = dig.panel4.add('button', [390,20,450,40], 'Browse');
dig.panel5.bt = dig.panel5.add('button', [390,20,450,40], 'Browse');
dig.bt1=dig.add('button', [150,330,200,350], 'OK');
dig.bt2=dig.add('button', [280,330,330,350], 'Cancle');
//------Button Event Handling Functions------//
dig.panel1.bt.onClick=function(){
filename1=File.openDialog("Open image 1","*.*");
if (filename1!=null)
dig.panel1.t.text = decodeURI(filename1.fsName);
}
dig.panel2.bt.onClick=function(){
filename2=File.openDialog("Open image 1","*.*");
if (filename2!=null)
dig.panel2.t.text = decodeURI(filename2.fsName);
}
dig.panel3.bt.onClick=function(){
filename3=File.openDialog("Open image 1","*.*");
if (filename3!=null)
dig.panel3.t.text = decodeURI(filename3.fsName);
}
dig.panel4.bt.onClick=function(){
filename4=File.openDialog("Open image 1","*.*");
if (filename4!=null)
dig.panel4.t.text = decodeURI(filename4.fsName);
}
dig.panel5.bt.onClick=function(){
filename5=File.openDialog("Open image 1","*.*");
if (filename5!=null)
dig.panel5.t.text = decodeURI(filename5.fsName);
}
//------Load Photos When "OK" Button Pressed------//
dig.bt1.onClick = function()
{
if( dig.panel1.t.text == '' || dig.panel2.t.text == '' || dig.panel3.t.text == '' || dig.panel4.t.text == '' || dig.panel5.t.text == '' ) {
alert("Not all six photos have been selected. Please check !");
return;
}
dig.close(1);
app.load(filename1);
app.load(filename2);
app.load(filename3);
app.load(filename4);
app.load(filename5);
}
dig.bt2.onClick = function(){
dig.close(1);}
dig.center();
dig.show();
// ------Make Photo Reference Variables------//
var p1=app.documents[1];
var p2=app.documents[2];
var p3=app.documents[3];
var p4=app.documents[4];
var p5=app.documents[5];
//------------Create A New A4 Document--------------//
var myFile = app.documents.add(842, 595, 72.0, "YangYang.psd");
//--------------Paste Background Layer-----------//
app.activeDocument=bgPhoto;
bgPhoto.selection.selectAll();
bgPhoto.selection.copy();
bgPhoto.selection.deselect();
app.activeDocument=myFile;
myFile.artLayers.add();
myFile.paste();
//------------Position Photos-----------//
PositionPic(p1, -170, -60,508,356.7);
PositionPic(p2, 255, 0,300,220);
PositionPic(p3, 175,220,148.4,89);
PositionPic(p4, 330,220, 148.4,89);
PositionPic(p5, 15,220, 148.4,89);
function PositionPic(picture, transX, transY, resizeW,resizeH)
{
app.activeDocument=picture;
picture.resizeImage(resizeW,resizeH);
picture.selection.selectAll();
picture.selection.copy();
picture.selection.deselect();
app.activeDocument=myFile;
myFile.artLayers.add();
myFile.paste();
myFile.activeLayer.translate(transX, transY);
}
//-------Create Text Layers & Add to docRef-------//
var textLayer1 = myFile.artLayers.add();
var textLayer2 = myFile.artLayers.add();
var textLayer3 = myFile.artLayers.add();
var textLayer4 = myFile.artLayers.add();
var textLayer5 = myFile.artLayers.add();
var textLayer6 = myFile.artLayers.add();
var whiteColor = new SolidColor;
whiteColor.rgb.hexValue = 'ffffff';
var blackColor = new SolidColor;
blackColor.rgb.hexValue = '000000';
createText (textLayer1, "Rhythm of Nature", 43,538, 'Centaur', 24, whiteColor,AntiAlias.SHARP,true,false,"Regular")
textLayer1.textItem.warpStyle = WarpStyle.FLAG;
createText (textLayer2, "Virtual", 562,134, "Lucida Fax", 18, blackColor,AntiAlias.STRONG,true,false,"Demibold")
createText (textLayer3, "GARDEN", 658,158, "Showcard Gothic", 30, whiteColor,AntiAlias.SHARP,true,false,"Regular")
createText (textLayer4, "UC", 615,83,'Kartika', 24, blackColor,AntiAlias.STRONG,true,false,"Regular")
createText (textLayer5, "C", 650,83, "Lucida Calligraphy", 24, blackColor,AntiAlias.STRONG,true,true,"Italian")
createText (textLayer6, "ampus",669,82, "Lucida Calligraphy", 18, blackColor,AntiAlias.STRONG,false,true,"Italian")
// Function to Create TextLayer and Set Styles of TextItems
function createText(textLayer, textString, posX, posY, fontName, textSize,
textColor,antiAlias,fauxBold,fauxItalic,style)
{
textLayer.kind=LayerKind.TEXT;
textLayer.textItem.contents = textString;
textLayer.textItem.position = Array(posX,posY);
textLayer.textItem.font = fontName;
textLayer.textItem.size = UnitValue(textSize, 'pt');
textLayer.textItem.color = textColor;
textLayer.textItem.antiAliasMethod = antiAlias;
textLayer.textItem.fauxBold = fauxBold;
textLayer.textItem.fauxBold = fauxItalic;
textLayer1.textItem.style=style;
}
//----Prepare for JPG Compression---//
var jpegOpts = new JPEGSaveOptions();
jpegOpts.quality = 10;
myFile.flatten();
myFile.bitsPerChannel = BitsPerChannelType.EIGHT;
//-----Save the Document------//
myFile.saveAs(new File(bgPhoto.path+"/YangYang.JPG"),jpegOpts);
//------Close All Images Without Saving Changes------//
bgPhoto.close(SaveOptions.DONOTSAVECHANGES);
p1.close(SaveOptions.DONOTSAVECHANGES);
p2.close(SaveOptions.DONOTSAVECHANGES);
p3.close(SaveOptions.DONOTSAVECHANGES);
p4.close(SaveOptions.DONOTSAVECHANGES);
p5.close(SaveOptions.DONOTSAVECHANGES);
评论0