This will do the job in seconds. It will prompt you for the picture. NB: The picture Must be the correct size and resolution 1.5" x 2" @150PPI
#target photoshop
var File1 = File.openDialog("Please select Photo ","*.*"); open(File1);
var doc = activeDocument;
var strtRulerUnits = app.preferences.rulerUnits;
var strtTypeUnits = app.preferences.typeUnits;
app.preferences.rulerUnits = Units.PIXELS;
app.preferences.typeUnits = TypeUnits.PIXELS;
if(doc.width < doc.height) doc.rotateCanvas(90);
if(doc.width ==300 && doc.height == 225){
doc.selection.selectAll();
doc.selection.copy();
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
processPic();
}else{
alert ("Sorry your picture is not 225 pixels x 300 pixels") }
app.preferences.rulerUnits = strtRulerUnits;
app.preferences.typeUnits = strtTypeUnits;
function processPic(){
var doc = app.documents.add(1200, 1800, 150, null, NewDocumentMode.RGB, DocumentFill.WHITE);
MakeSelection(600,675,900,900);
MakeSelection(900,675,1200,900);
MakeSelection(300,675,600,900);
MakeSelection(0,675,300,900);
MakeSelection(900,900,1200,1125);
MakeSelection(600,900,900,1125);
MakeSelection(300,900,600,1125);
MakeSelection(0,900,300,1125);
MakeSelection(900,1125,1200,1350);
MakeSelection(600,1125,900,1350);
MakeSelection(300,1125,600,1350);
MakeSelection(0,1125,300,1350);
MakeSelection(900,1350,1200,1575);
MakeSelection(600,1350,900,1575);
MakeSelection(300,1350,600,1575);
MakeSelection(0,1350,300,1575);
MakeSelection(900,1575,1200,1800);
MakeSelection(600,1575,900,1800);
MakeSelection(300,1575,600,1800);
MakeSelection(0,1575,300,1800);
MakeSelection(900,450,1200,675);
MakeSelection(600,450,900,675);
MakeSelection(300,450,600,675);
MakeSelection(0,450,300,675);
MakeSelection(900,225,1200,450);
MakeSelection(600,225,900,450);
MakeSelection(300,225,600,450);
MakeSelection(0,225,300,450);
MakeSelection(900,0,1200,225);
MakeSelection(600,0,900,225);
MakeSelection(300,0,600,225);
MakeSelection(0,0,300,225);
activeDocument.flatten();
}
function MakeSelection(Left,Top,Right,Bottom){
var selRegion = Array(
Array(Left, Top),
Array(Right, Top),
Array(Right, Bottom),
Array(Left, Bottom),
Array(Left, Top)
);
activeDocument.selection.select(selRegion);
activeDocument.paste();
activeDocument.selection.deselect();
}
Passport Photos are 35mm x 45mm in the UK so here is another script Crop picture using 35mm x 45mm @ 300ppi
Save picture and then run script.
This will create a 6"x4" with 8 pictures with white borders and crop marks.
#target photoshop
var File1 = File.openDialog("Please select Photo ","*.*"); open(File1);
var doc = activeDocument;
var strtRulerUnits = app.preferences.rulerUnits;
var strtTypeUnits = app.preferences.typeUnits;
app.preferences.rulerUnits = Units.PIXELS;
app.preferences.typeUnits = TypeUnits.PIXELS;
if(doc.width > doc.height) doc.rotateCanvas(90);
if (doc.resolution != 300) activeDocument.resizeImage(undefined, undefined, 300, ResampleMethod.NONE);
if(doc.width ==413 && doc.height == 531){
app.activeDocument.resizeCanvas(450, 600, AnchorPosition.MIDDLECENTER); cropMarks();
doc.selection.selectAll();
doc.selection.copy();
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
processPic();
}else{
alert ("Sorry your picture is not 413 pixels x 531 pixels") }
app.preferences.rulerUnits = strtRulerUnits;
app.preferences.typeUnits = strtTypeUnits;
function processPic(){
var doc = app.documents.add(1800, 1200, 300, null, NewDocumentMode.RGB, DocumentFill.WHITE);
MakeSelection(1350,600,1800,1200);
MakeSelection(900,600,1350,1200);
MakeSelection(450,600,900,1200);
MakeSelection(0,600,450,1200);
MakeSelection(1350,0,1800,600);
MakeSelection(900,0,1350,600);
MakeSelection(450,0,900,600);
MakeSelection(0,0,450,600);
activeDocument.flatten();
}
function MakeSelection(Left,Top,Right,Bottom){
var selRegion = Array(
Array(Left, Top),
Array(Right, Top),
Array(Right, Bottom),
Array(Left, Bottom),
Array(Left, Top)
);
activeDocument.selection.select(selRegion);
activeDocument.paste();
activeDocument.selection.deselect();
}
function cropMarks(){
var Width = doc.width;
var Height = doc.height;
var HalfInch = doc.resolution/2;
selectSingleLine(0,0,1,HalfInch);
Stroke();
selectSingleLine(0,Width-(HalfInch),1,Width);
Stroke();
selectSingleLine(Height-1,0,Height,HalfInch);
Stroke();
selectSingleLine(Height-1,Width-HalfInch,Height,Width);
Stroke();
selectSingleLine(0,0,HalfInch,1);
Stroke();
selectSingleLine(Height-HalfInch,0,Height,1);
Stroke();
selectSingleLine(Height-HalfInch,Width-1,Height,Width);
Stroke();
selectSingleLine(0,Width-1,HalfInch,Width);
Stroke();
}
function Stroke(){
var Black = new SolidColor;
Black.rgb.hexValue = ‘000000’;
activeDocument.selection.stroke(Black,1);
activeDocument.selection.deselect();
}
function selectSingleLine(Top,Left,Bottom,Right) {
function cTID(s) { return app.charIDToTypeID(s); };
function sTID(s) { return app.stringIDToTypeID(s); };
var desc11 = new ActionDescriptor();
var ref6 = new ActionReference();
ref6.putProperty( cTID(‘Chnl’), cTID(‘fsel’) );
desc11.putReference( cTID(‘null’), ref6 );
var desc12 = new ActionDescriptor();
desc12.putUnitDouble( cTID(‘Top ‘), cTID(‘#Pxl’), Top ); desc12.putUnitDouble( cTID(‘Left’), cTID(‘#Pxl’), Left ); desc12.putUnitDouble( cTID(‘Btom’), cTID(‘#Pxl’), Bottom ); desc12.putUnitDouble( cTID(‘Rght’), cTID(‘#Pxl’), Right ); desc11.putObject( cTID(‘T ‘), cTID(‘Rctn’), desc12 );
executeAction( cTID(‘setd’), desc11, DialogModes.NO );
};