• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
1

Portraits Cropping Automation

Community Beginner ,
May 27, 2019 May 27, 2019

Copy link to clipboard

Copied

Hello Everyone,

 

I need your help!

 

Actually, I have a bulk of portraits images. And I want to crop them all on the same position, same in size, head size, eye position so they all can seem consistent.  The required final dimension will be
8x10. I do not want to crop them manually. I need an automated process for the same. Can you please suggest to me so I can avoid manual work and save a lot of time.

 

Thank You in Advance

TOPICS
Actions and scripting

Views

5.0K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Explorer ,
Sep 29, 2021 Sep 29, 2021

Copy link to clipboard

Copied

^^ I know that. I said adding pictures in the script. But thank you.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 29, 2021 Sep 29, 2021

Copy link to clipboard

Copied

I'm sorry that I didn't understand it well.
Thank you for explaining it in an easy-to-understand way.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 30, 2021 Sep 30, 2021

Copy link to clipboard

Copied

This is what it's taking to convert your image to a script: I have to create it out of line shapes all on one layer. So to speed up the processing I make a dot and put it on each end of each line segment.

port screen.jpgport screen 2.jpg

Then I use this script to create code that I can cut and paste into another script:

#target photoshop
var doc = activeDocument;
var layB = doc.layers[0].bounds
var x1 = layB[0].value +3
var y1 = layB[1].value +3
var layA = doc.layers[1].bounds
var x2 = layA[0].value +3
var y2 = layA[1].value +3
$.writeln('makeLines ( vAdj (' + x1 +'), vAdj ('+ y1 + '), vAdj (' +x2 + '), vAdj (' + y2 + '));')


Then there is the script so far, just to create the face. It's not nearly half done. You can try it and see how slow it's getting. In my opinion, there are too many unnessary lines in the face. You really don't need that many just to size the face to a portrait to have the original script crop the portrait.

#target photoshop
var doc = activeDocument;

      var idslct = charIDToTypeID( "slct" );
          var desc15 = new ActionDescriptor();
          var idnull = charIDToTypeID( "null" );
              var ref6 = new ActionReference();
              var idrectangleTool = stringIDToTypeID( "rectangleTool" );
              ref6.putClass( idrectangleTool );
          desc15.putReference( idnull, ref6 );
          var iddontRecord = stringIDToTypeID( "dontRecord" );
          desc15.putBoolean( iddontRecord, true );
          var idforceNotify = stringIDToTypeID( "forceNotify" );
          desc15.putBoolean( idforceNotify, true );
      executeAction( idslct, desc15, DialogModes.NO );
      
eyes1("Mk  ", 594, 595, 642, 643);
eyes2("SbtF", 600, 601, 636, 637);
eyes2("AddT", 608, 609, 628, 629);
eyes2("SbtF", 613, 614, 623, 624);

eyes2("AddT", 594, 857, 642, 905);
eyes2("SbtF", 600, 863, 636, 899);
eyes2("AddT", 608, 871, 628, 891);
eyes2("SbtF", 613, 876, 623, 886);

makeLines ( vAdj (859), vAdj (319), vAdj (639), vAdj (319));
makeLines ( vAdj (501), vAdj (419), vAdj (639), vAdj (319));
makeLines ( vAdj (859), vAdj (319), vAdj (997), vAdj (419));
makeLines ( vAdj (899), vAdj (350), vAdj (750), vAdj (400));
makeLines ( vAdj (750), vAdj (400), vAdj (599), vAdj (350));
makeLines ( vAdj (656), vAdj (529), vAdj (701), vAdj (386));
makeLines ( vAdj (796), vAdj (386), vAdj (842), vAdj (529));
makeLines ( vAdj (842), vAdj (529), vAdj (656), vAdj (529));
makeLines ( vAdj (501), vAdj (580), vAdj (501), vAdj (419));
makeLines ( vAdj (997), vAdj (419), vAdj (997), vAdj (580));
makeLines ( vAdj (937), vAdj (500), vAdj (970), vAdj (400));
makeLines ( vAdj (937), vAdj (500), vAdj (842), vAdj (529));
makeLines ( vAdj (937), vAdj (500), vAdj (997), vAdj (580));
makeLines ( vAdj (774), vAdj (630), vAdj (842), vAdj (529));
makeLines ( vAdj (562), vAdj (500), vAdj (528), vAdj (400));
makeLines ( vAdj (562), vAdj (500), vAdj (656), vAdj (529));
makeLines ( vAdj (501), vAdj (580), vAdj (562), vAdj (500));
makeLines ( vAdj (656), vAdj (529), vAdj (726), vAdj (630));
makeLines ( vAdj (656), vAdj (529), vAdj (726), vAdj (630));
makeLines ( vAdj (562), vAdj (537), vAdj (501), vAdj (580));
makeLines ( vAdj (938), vAdj (537), vAdj (997), vAdj (580));
makeLines ( vAdj (687), vAdj (577), vAdj (562), vAdj (537));
makeLines ( vAdj (676), vAdj (599), vAdj (690), vAdj (580));
makeLines ( vAdj (822), vAdj (599), vAdj (810), vAdj (580));
makeLines ( vAdj (820), vAdj (597), vAdj (938), vAdj (562));
makeLines ( vAdj (994), vAdj (577), vAdj (938), vAdj (562));
makeLines ( vAdj (994), vAdj (577), vAdj (881), vAdj (580));
makeLines ( vAdj (807), vAdj (580), vAdj (938), vAdj (537));
makeLines ( vAdj (559), vAdj (559), vAdj (677), vAdj (600));
makeLines ( vAdj (498), vAdj (577), vAdj (563), vAdj (559));
makeLines ( vAdj (498), vAdj (577), vAdj (619), vAdj (580));
makeLines ( vAdj (786), vAdj (651), vAdj (824), vAdj (597));
makeLines ( vAdj (878), vAdj (580), vAdj (814), vAdj (630));
makeLines ( vAdj (616), vAdj (579), vAdj (686), vAdj (630));
makeLines ( vAdj (713), vAdj (649), vAdj (677), vAdj (600));
makeLines ( vAdj (946), vAdj (651), vAdj (997), vAdj (580));
makeLines ( vAdj (553), vAdj (650), vAdj (501), vAdj (580));
makeLines ( vAdj (479), vAdj (650), vAdj (501), vAdj (580));
makeLines ( vAdj (1022), vAdj (650), vAdj (997), vAdj (580));
makeLines ( vAdj (932), vAdj (627), vAdj (997), vAdj (580));
makeLines ( vAdj (568), vAdj (627), vAdj (501), vAdj (580));
makeLines ( vAdj (583), vAdj (609), vAdj (568), vAdj (627));
makeLines ( vAdj (621), vAdj (595), vAdj (583), vAdj (609));
makeLines ( vAdj (677), vAdj (637), vAdj (621), vAdj (595));
makeLines ( vAdj (677), vAdj (637), vAdj (574), vAdj (637));
makeLines ( vAdj (574), vAdj (637), vAdj (568), vAdj (627));
makeLines ( vAdj (562), vAdj (637), vAdj (621), vAdj (657));
makeLines ( vAdj (677), vAdj (637), vAdj (621), vAdj (657));
makeLines ( vAdj (677), vAdj (637), vAdj (639), vAdj (669));
makeLines ( vAdj (604), vAdj (669), vAdj (639), vAdj (669));
makeLines ( vAdj (562), vAdj (637), vAdj (604), vAdj (669));
makeLines ( vAdj (686), vAdj (630), vAdj (694), vAdj (650));
makeLines ( vAdj (677), vAdj (650), vAdj (694), vAdj (650));
makeLines ( vAdj (713), vAdj (650), vAdj (630), vAdj (711));
makeLines ( vAdj (713), vAdj (650), vAdj (671), vAdj (711));
makeLines ( vAdj (713), vAdj (650), vAdj (713), vAdj (787));
makeLines ( vAdj (726), vAdj (630), vAdj (726), vAdj (747));


function makeLines(leftG,topG,rightG,bottomG){
      var idAddT = charIDToTypeID( "AddT" );
          var desc140 = new ActionDescriptor();
          var idnull = charIDToTypeID( "null" );
              var ref39 = new ActionReference();
              var idPath = charIDToTypeID( "Path" );
              var idOrdn = charIDToTypeID( "Ordn" );
              var idTrgt = charIDToTypeID( "Trgt" );
              ref39.putEnumerated( idPath, idOrdn, idTrgt );
          desc140.putReference( idnull, ref39 );
          var idT = charIDToTypeID( "T   " );
              var desc141 = new ActionDescriptor();
              var idStrt = charIDToTypeID( "Strt" );
                  var desc142 = new ActionDescriptor();
                  var idHrzn = charIDToTypeID( "Hrzn" );
                  var idPxl = charIDToTypeID( "#Pxl" );
                  desc142.putUnitDouble( idHrzn, idPxl, leftG );
                  var idVrtc = charIDToTypeID( "Vrtc" );
                  var idPxl = charIDToTypeID( "#Pxl" );
                  desc142.putUnitDouble( idVrtc, idPxl, topG );
              var idPnt = charIDToTypeID( "Pnt " );
              desc141.putObject( idStrt, idPnt, desc142 );
              var idEnd = charIDToTypeID( "End " );
                  var desc143 = new ActionDescriptor();
                  var idHrzn = charIDToTypeID( "Hrzn" );
                  var idPxl = charIDToTypeID( "#Pxl" );
                  desc143.putUnitDouble( idHrzn, idPxl, rightG );
                  var idVrtc = charIDToTypeID( "Vrtc" );
                  var idPxl = charIDToTypeID( "#Pxl" );
                  desc143.putUnitDouble( idVrtc, idPxl, bottomG );
              var idPnt = charIDToTypeID( "Pnt " );
              desc141.putObject( idEnd, idPnt, desc143 );
              var idWdth = charIDToTypeID( "Wdth" );
              var idPxl = charIDToTypeID( "#Pxl" );
              desc141.putUnitDouble( idWdth, idPxl, 6.000000 );
          var idLn = charIDToTypeID( "Ln  " );
          desc140.putObject( idT, idLn, desc141 );
      executeAction( idAddT, desc140, DialogModes.NO );      
      }//end function makeLines

function vAdj(num){//adjust vector layer to size of document
      var factor = 2832/parseFloat (doc.width)//2832 is size of test doc.
      //return num*factor
      return num
      };//end function vAdj
  
function eyes1(mode1, top, left, bottom, right)  {
// =======================================================
    var idMk = charIDToTypeID( mode1 );
        var desc148 = new ActionDescriptor();
        var idnull = charIDToTypeID( "null" );
            var ref31 = new ActionReference();
            var idcontentLayer = stringIDToTypeID( "contentLayer" );
            ref31.putClass( idcontentLayer );
        desc148.putReference( idnull, ref31 );
        var idUsng = charIDToTypeID( "Usng" );
            var desc149 = new ActionDescriptor();
            var idType = charIDToTypeID( "Type" );
                var desc150 = new ActionDescriptor();
                var idClr = charIDToTypeID( "Clr " );
                    var desc151 = new ActionDescriptor();
                    var idRd = charIDToTypeID( "Rd  " );
                    desc151.putDouble( idRd, 255.000000 );
                    var idGrn = charIDToTypeID( "Grn " );
                    desc151.putDouble( idGrn, 1.003891 );
                    var idBl = charIDToTypeID( "Bl  " );
                    desc151.putDouble( idBl, 1.027237 );
                var idRGBC = charIDToTypeID( "RGBC" );
                desc150.putObject( idClr, idRGBC, desc151 );
            var idsolidColorLayer = stringIDToTypeID( "solidColorLayer" );
            desc149.putObject( idType, idsolidColorLayer, desc150 );
            var idShp = charIDToTypeID( "Shp " );
                var desc152 = new ActionDescriptor();
                var idunitValueQuadVersion = stringIDToTypeID( "unitValueQuadVersion" );
                desc152.putInteger( idunitValueQuadVersion, 1 );
                var idTop = charIDToTypeID( "Top " );
                var idPxl = charIDToTypeID( "#Pxl" );
                desc152.putUnitDouble( idTop, idPxl, top );
                var idLeft = charIDToTypeID( "Left" );
                var idPxl = charIDToTypeID( "#Pxl" );
                desc152.putUnitDouble( idLeft, idPxl, left );
                var idBtom = charIDToTypeID( "Btom" );
                var idPxl = charIDToTypeID( "#Pxl" );
                desc152.putUnitDouble( idBtom, idPxl, bottom );
                var idRght = charIDToTypeID( "Rght" );
                var idPxl = charIDToTypeID( "#Pxl" );
                desc152.putUnitDouble( idRght, idPxl, right );
            var idElps = charIDToTypeID( "Elps" );
            desc149.putObject( idShp, idElps, desc152 );
            var idstrokeStyle = stringIDToTypeID( "strokeStyle" );
                var desc153 = new ActionDescriptor();
                var idstrokeStyleVersion = stringIDToTypeID( "strokeStyleVersion" );
                desc153.putInteger( idstrokeStyleVersion, 2 );
                var idstrokeEnabled = stringIDToTypeID( "strokeEnabled" );
                desc153.putBoolean( idstrokeEnabled, false );
                var idfillEnabled = stringIDToTypeID( "fillEnabled" );
                desc153.putBoolean( idfillEnabled, true );
                var idstrokeStyleLineWidth = stringIDToTypeID( "strokeStyleLineWidth" );
                var idPxl = charIDToTypeID( "#Pxl" );
                desc153.putUnitDouble( idstrokeStyleLineWidth, idPxl, 6.000000 );
                var idstrokeStyleLineDashOffset = stringIDToTypeID( "strokeStyleLineDashOffset" );
                var idPnt = charIDToTypeID( "#Pnt" );
                desc153.putUnitDouble( idstrokeStyleLineDashOffset, idPnt, 0.000000 );
                var idstrokeStyleMiterLimit = stringIDToTypeID( "strokeStyleMiterLimit" );
                desc153.putDouble( idstrokeStyleMiterLimit, 100.000000 );
                var idstrokeStyleLineCapType = stringIDToTypeID( "strokeStyleLineCapType" );
                var idstrokeStyleLineCapType = stringIDToTypeID( "strokeStyleLineCapType" );
                var idstrokeStyleButtCap = stringIDToTypeID( "strokeStyleButtCap" );
                desc153.putEnumerated( idstrokeStyleLineCapType, idstrokeStyleLineCapType, idstrokeStyleButtCap );
                var idstrokeStyleLineJoinType = stringIDToTypeID( "strokeStyleLineJoinType" );
                var idstrokeStyleLineJoinType = stringIDToTypeID( "strokeStyleLineJoinType" );
                var idstrokeStyleMiterJoin = stringIDToTypeID( "strokeStyleMiterJoin" );
                desc153.putEnumerated( idstrokeStyleLineJoinType, idstrokeStyleLineJoinType, idstrokeStyleMiterJoin );
                var idstrokeStyleLineAlignment = stringIDToTypeID( "strokeStyleLineAlignment" );
                var idstrokeStyleLineAlignment = stringIDToTypeID( "strokeStyleLineAlignment" );
                var idstrokeStyleAlignCenter = stringIDToTypeID( "strokeStyleAlignCenter" );
                desc153.putEnumerated( idstrokeStyleLineAlignment, idstrokeStyleLineAlignment, idstrokeStyleAlignCenter );
                var idstrokeStyleScaleLock = stringIDToTypeID( "strokeStyleScaleLock" );
                desc153.putBoolean( idstrokeStyleScaleLock, false );
                var idstrokeStyleStrokeAdjust = stringIDToTypeID( "strokeStyleStrokeAdjust" );
                desc153.putBoolean( idstrokeStyleStrokeAdjust, false );
                var idstrokeStyleLineDashSet = stringIDToTypeID( "strokeStyleLineDashSet" );
                    var list21 = new ActionList();
                desc153.putList( idstrokeStyleLineDashSet, list21 );
                var idstrokeStyleBlendMode = stringIDToTypeID( "strokeStyleBlendMode" );
                var idBlnM = charIDToTypeID( "BlnM" );
                var idNrml = charIDToTypeID( "Nrml" );
                desc153.putEnumerated( idstrokeStyleBlendMode, idBlnM, idNrml );
                var idstrokeStyleOpacity = stringIDToTypeID( "strokeStyleOpacity" );
                var idPrc = charIDToTypeID( "#Prc" );
                desc153.putUnitDouble( idstrokeStyleOpacity, idPrc, 100.000000 );
                var idstrokeStyleContent = stringIDToTypeID( "strokeStyleContent" );
                    var desc154 = new ActionDescriptor();
                    var idClr = charIDToTypeID( "Clr " );
                        var desc155 = new ActionDescriptor();
                        var idRd = charIDToTypeID( "Rd  " );
                        desc155.putDouble( idRd, 255.000000 );
                        var idGrn = charIDToTypeID( "Grn " );
                        desc155.putDouble( idGrn, 0.003891 );
                        var idBl = charIDToTypeID( "Bl  " );
                        desc155.putDouble( idBl, 0.003891 );
                    var idRGBC = charIDToTypeID( "RGBC" );
                    desc154.putObject( idClr, idRGBC, desc155 );
                var idsolidColorLayer = stringIDToTypeID( "solidColorLayer" );
                desc153.putObject( idstrokeStyleContent, idsolidColorLayer, desc154 );
                var idstrokeStyleResolution = stringIDToTypeID( "strokeStyleResolution" );
                desc153.putDouble( idstrokeStyleResolution, 762.000000 );
            var idstrokeStyle = stringIDToTypeID( "strokeStyle" );
            desc149.putObject( idstrokeStyle, idstrokeStyle, desc153 );
        var idcontentLayer = stringIDToTypeID( "contentLayer" );
        desc148.putObject( idUsng, idcontentLayer, desc149 );
        var idLyrI = charIDToTypeID( "LyrI" );
        desc148.putInteger( idLyrI, 149 );
    executeAction( idMk, desc148, DialogModes.NO );
    }

// =======================================================
function eyes2(mode1, top, left, bottom, right)  {
var idSbtF = charIDToTypeID( mode1 );
    var desc157 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
        var ref32 = new ActionReference();
        var idPath = charIDToTypeID( "Path" );
        var idOrdn = charIDToTypeID( "Ordn" );
        var idTrgt = charIDToTypeID( "Trgt" );
        ref32.putEnumerated( idPath, idOrdn, idTrgt );
    desc157.putReference( idnull, ref32 );
    var idT = charIDToTypeID( "T   " );
        var desc158 = new ActionDescriptor();
        var idunitValueQuadVersion = stringIDToTypeID( "unitValueQuadVersion" );
        desc158.putInteger( idunitValueQuadVersion, 1 );
        var idTop = charIDToTypeID( "Top " );
        var idPxl = charIDToTypeID( "#Pxl" );
        desc158.putUnitDouble( idTop, idPxl, top );
        var idLeft = charIDToTypeID( "Left" );
        var idPxl = charIDToTypeID( "#Pxl" );
        desc158.putUnitDouble( idLeft, idPxl, left );
        var idBtom = charIDToTypeID( "Btom" );
        var idPxl = charIDToTypeID( "#Pxl" );
        desc158.putUnitDouble( idBtom, idPxl, bottom );
        var idRght = charIDToTypeID( "Rght" );
        var idPxl = charIDToTypeID( "#Pxl" );
        desc158.putUnitDouble( idRght, idPxl, right );
    var idElps = charIDToTypeID( "Elps" );
    desc157.putObject( idT, idElps, desc158 );
executeAction( idSbtF, desc157, DialogModes.NO );


    }

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 30, 2021 Sep 30, 2021

Copy link to clipboard

Copied

Instead of drawing one by one, can't you just bring up the image I sent you?

 

 

스크린샷 2021-10-01 오후 2.16.22.png

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 30, 2021 Sep 30, 2021

Copy link to clipboard

Copied

I'll see what I can do.

 

 

Okay here's the script. To have it run, you have to create a folder on your desktop named: "Portrait crop overlays" and you have to put all the files you sent me in that folder. This script will change your preferences to that it will size smartobjects when placing.

#target photoshop

var oldPref = app.preferences.rulerUnits;//stores old measurement preferences so that they can be reset when the script is done.
app.preferences.rulerUnits = Units.PIXELS;

var overlayFolder = new Folder('~/desktop/Portrait crop overlays');
var overlayFile

var docSize = new Array('3.3X4.8', '3.5X4.5 part 1', '3.5X4.5 part 2', '3X4', '5X5', '5X7');
var cropBounds = new Array();

var cropRatio
var runProg = false;
var tempLayer
var docResize = new Array();
var proceedRunning = true;

var dlg = new Window('dialog','Portriat Guides');
      dlg.alignChildren = ['left','top'];
      dlg.sizeGp = dlg.add('group');
            dlg.sizeGp.orientation = 'row';
            dlg.sizeGp.alignChildren = ['left','top'];
            var sizeDL = dlg.sizeGp.add('dropdownlist',undefined,docSize);
                  sizeDL.selection = 0;
            dlg.sizeGp.docDPIsTxt = dlg.sizeGp.add('statictext',undefined,'DPI:');
            var docDPIeTxt = dlg.sizeGp.add('edittext',undefined,300);
                  docDPIeTxt.size = [50,20];
                  docDPIeTxt.onChange = function(){textToNum(25,3000,this,'int')};
                  
            dlg.sizeGp.crop = dlg.sizeGp.add('radiobutton',undefined,'Crop');
            dlg.sizeGp.guides = dlg.sizeGp.add('radiobutton',undefined,'Add fixed Guides');
            dlg.sizeGp.crop.value = true
                  
      dlg.buttonGp = dlg.add('group');
            dlg.buttonGp.orientation = 'row';
            dlg.buttonGp.alignChildren = ['left','top'];
            
            dlg.buttonGp.okBtn = dlg.buttonGp.add('button',undefined,'Ok');
                  dlg.buttonGp.okBtn.onClick = function(){
                        if(proceedRunning){
                              dlg.close();
                              switch(parseInt(sizeDL.selection)){
                                    case 0:
                                          docResize[0] = 3.3
                                          break;
                                    case 1:
                                          docResize[0] = 3.5
                                          break;      
                                    case 2:
                                          docResize[0] = 3.5
                                          break;  
                                    case 3:
                                          docResize[0] = 3
                                          break;      
                                    case 4:
                                          docResize[0] = 5
                                          break;   
                                    case 5:
                                          docResize[0] = 5
                                          break;                                            
                                        
                                    };//end switch
                              docResize[1] = parseInt(docDPIeTxt.text);
                              runProg = true;
                              };
                        };
            
            dlg.buttonGp.cancelBtn = dlg.buttonGp.add('button',undefined,'Cancel');
                  dlg.buttonGp.cancelBtn.onClick = function(){dlg.close()};
                            
dlg.show();

if(runProg && app.documents.length>0){
      var doc = activeDocument;
      createTempLayer()
      
      
      switch(parseInt(sizeDL.selection)){ 
            case 0://3.3X4.8
                  overlayFile = new File(overlayFolder +'/3.3X4.8.jpg')
                  placeOverlay (overlayFile);
                  blendIf ();
                  break;              
            case 1://3.5X4.5 part 1
                  overlayFile = new File(overlayFolder +'/3.5X4.5[part1].jpg')
                  placeOverlay (overlayFile);
                  blendIf ();                  break;  
            case 2://3.5X4.5 part  2
                  overlayFile = new File(overlayFolder +'/3.5X4.5[part2].jpg')
                  placeOverlay (overlayFile);
                  blendIf ();            
                  break;
            case 3://3X4
                  overlayFile = new File(overlayFolder +'/3x4cm.jpg')
                  placeOverlay (overlayFile);
                  blendIf ();
                  break;    
            case 4://5X5
                  overlayFile = new File(overlayFolder +'/5x5cm.jpg')
                  placeOverlay (overlayFile);
                  blendIf ();
                  break;                     
            case 5://5X7
                  overlayFile = new File(overlayFolder +'/5x7cm.jpg')
                  placeOverlay (overlayFile);
                  blendIf ();
                  break;                                          
            };//end switch
      tempLayer = doc.activeLayer       
      //setLayer ()
 
    
      transformLayer();
      var cropBounds = [parseFloat (tempLayer.bounds[0]),parseFloat (tempLayer.bounds[1]),parseFloat (tempLayer.bounds[2]),parseFloat (tempLayer.bounds[3])];
      if(dlg.sizeGp.crop.value){
            cropPort ();
            tempLayer.remove();
            app.preferences.rulerUnits = Units.CM;
            var useRes = 2.54 * docResize[1];
            doc.resizeImage (docResize[0], undefined, useRes)
            }//end if
      else{
            vertG (cropBounds[0])
            vertG (cropBounds[2])
            horG (cropBounds[1])
            horG (cropBounds[3])
            tempLayer.remove();
            };//end else
            
      app.preferences.rulerUnits = oldPref
      };//end function runProgram

function createTempLayer(){

    }

function setLayer(){
      // Set Opacity =======================================================
     var idsetd = charIDToTypeID( "setd" );
          var desc38 = new ActionDescriptor();
          var idnull = charIDToTypeID( "null" );
              var ref17 = new ActionReference();
              var idLyr = charIDToTypeID( "Lyr " );
              var idOrdn = charIDToTypeID( "Ordn" );
              var idTrgt = charIDToTypeID( "Trgt" );
              ref17.putEnumerated( idLyr, idOrdn, idTrgt );
          desc38.putReference( idnull, ref17 );
          var idT = charIDToTypeID( "T   " );
              var desc39 = new ActionDescriptor();
              var idOpct = charIDToTypeID( "Opct" );
              var idPrc = charIDToTypeID( "#Prc" );
              desc39.putUnitDouble( idOpct, idPrc, 35.000000 );
          var idLyr = charIDToTypeID( "Lyr " );
          desc38.putObject( idT, idLyr, desc39 );
      executeAction( idsetd, desc38, DialogModes.NO );

      // Deselect paths prior to transform=======================================================
      var idDslc = charIDToTypeID( "Dslc" );
          var desc40 = new ActionDescriptor();
          var idnull = charIDToTypeID( "null" );
              var ref18 = new ActionReference();
              var idPath = charIDToTypeID( "Path" );
              ref18.putClass( idPath );
          desc40.putReference( idnull, ref18 );
      executeAction( idDslc, desc40, DialogModes.NO );

      // =======================================================
      var idslct = charIDToTypeID( "slct" );
          var desc43 = new ActionDescriptor();
          var idnull = charIDToTypeID( "null" );
              var ref20 = new ActionReference();
              var idHstS = charIDToTypeID( "HstS" );
              var idOrdn = charIDToTypeID( "Ordn" );
              var idPrvs = charIDToTypeID( "Prvs" );
              ref20.putEnumerated( idHstS, idOrdn, idPrvs );
          desc43.putReference( idnull, ref20 );
      executeAction( idslct, desc43, DialogModes.NO );
      
      tempLayer = doc.activeLayer;
   
      };//end function setlayer


    function transformLayer(){
    try{
        var desc = new ActionDescriptor();
            var ref = new ActionReference();
            ref.putEnumerated( app.charIDToTypeID('Lyr '), app.charIDToTypeID('Ordn'), app.charIDToTypeID('Trgt') );
        desc.putReference( app.charIDToTypeID('null'), ref );
        executeAction( app.charIDToTypeID('Trnf'), desc, DialogModes.ALL );
        }catch(e){
      if (e.toString().match(/User cancelled/)) {
           return -1;
           }else{
          throw e;
          }
      }
      app.displayDialogs = DialogModes.NO;
    };

function cropPort(){

      // =======================================================
      var idslct = charIDToTypeID( "slct" );
          var desc3 = new ActionDescriptor();
          var idnull = charIDToTypeID( "null" );
              var ref1 = new ActionReference();
              var idcropTool = stringIDToTypeID( "cropTool" );
              ref1.putClass( idcropTool );
          desc3.putReference( idnull, ref1 );
          var iddontRecord = stringIDToTypeID( "dontRecord" );
          desc3.putBoolean( iddontRecord, true );
          var idforceNotify = stringIDToTypeID( "forceNotify" );
          desc3.putBoolean( idforceNotify, true );
      executeAction( idslct, desc3, DialogModes.NO );

      // =======================================================
      var idCrop = charIDToTypeID( "Crop" );
          var desc4 = new ActionDescriptor();
          var idT = charIDToTypeID( "T   " );
              var desc5 = new ActionDescriptor();
              var idTop = charIDToTypeID( "Top " );
              var idPxl = charIDToTypeID( "#Pxl" );
              desc5.putUnitDouble( idTop, idPxl, cropBounds[1] );
              var idLeft = charIDToTypeID( "Left" );
              var idPxl = charIDToTypeID( "#Pxl" );
              desc5.putUnitDouble( idLeft, idPxl, cropBounds[0] );
              var idBtom = charIDToTypeID( "Btom" );
              var idPxl = charIDToTypeID( "#Pxl" );
              desc5.putUnitDouble( idBtom, idPxl, cropBounds[3] );
              var idRght = charIDToTypeID( "Rght" );
              var idPxl = charIDToTypeID( "#Pxl" );
              desc5.putUnitDouble( idRght, idPxl, cropBounds[2] );
          var idRctn = charIDToTypeID( "Rctn" );
          desc4.putObject( idT, idRctn, desc5 );
          var idAngl = charIDToTypeID( "Angl" );
          var idAng = charIDToTypeID( "#Ang" );
          desc4.putUnitDouble( idAngl, idAng, 0.000000 );
          var idDlt = charIDToTypeID( "Dlt " );
          desc4.putBoolean( idDlt, false );
          var idcropAspectRatioModeKey = stringIDToTypeID( "cropAspectRatioModeKey" );
          var idcropAspectRatioModeClass = stringIDToTypeID( "cropAspectRatioModeClass" );
          var idunconstrained = stringIDToTypeID( "unconstrained" );
          desc4.putEnumerated( idcropAspectRatioModeKey, idcropAspectRatioModeClass, idunconstrained );
      executeAction( idCrop, desc4, DialogModes.NO );
};//end function cropPort

function textToNum(sMin,sMax,e,par){
	var sHold = sMin;
	
	if(par == 'int'){
		if(isNaN(parseInt(e.text))){
                    proceedRunning = false;
			alert('"' + e.text + '" is not a number\nEnter a value between ' + sMin + '-' + sMax );
			e.text = sMin};
		else{sHold = parseInt(e.text)
			if(sHold < sMin){
                        proceedRunning = false;
				rangeAlert();
				sHold = sMin;				
				}
                  else{proceedRunning = true};
			if(sHold > sMax){
                        proceedRunning = false;
				rangeAlert();
				sHold = sMax;
				}
                  else{proceedRunning = true}
			e.text = sHold;
			};	//end else
		};//end if par
	else{
		if(isNaN(parseFloat(e.text))){
			alert('"' + e.text + '" is not a number\nEnter a value between ' + sMin + '-' + sMax );
			e.text = sMin};
		else{sHold = parseFloat(e.text)
			if(sHold < sMin){
				rangeAlert();
				sHold = sMin;
				};
			if(sHold > sMax){
				rangeAlert();
				sHold = sMax;
				};
			e.text = sHold;
			};	//end else
		};//end else par
	function rangeAlert(){
            proceedRunning = false;
            alert('Number range must be between ' + sMin + '-' + sMax)
            }; 
};//end function textToNum

function vertG(position){
      // =======================================================
      var idMk = charIDToTypeID( "Mk  " );
          var desc3 = new ActionDescriptor();
          var idNw = charIDToTypeID( "Nw  " );
              var desc4 = new ActionDescriptor();
              var idPstn = charIDToTypeID( "Pstn" );
              var idPxl = charIDToTypeID( "#Pxl" );
              desc4.putUnitDouble( idPstn, idPxl, position );
              var idOrnt = charIDToTypeID( "Ornt" );
              var idOrnt = charIDToTypeID( "Ornt" );
              var idVrtc = charIDToTypeID( "Vrtc" );
              desc4.putEnumerated( idOrnt, idOrnt, idVrtc );
          var idGd = charIDToTypeID( "Gd  " );
          desc3.putObject( idNw, idGd, desc4 );
      executeAction( idMk, desc3, DialogModes.NO );
      };//end function vertG

function horG(position){

      // =======================================================
      var idMk = charIDToTypeID( "Mk  " );
          var desc5 = new ActionDescriptor();
          var idNw = charIDToTypeID( "Nw  " );
              var desc6 = new ActionDescriptor();
              var idPstn = charIDToTypeID( "Pstn" );
              var idPxl = charIDToTypeID( "#Pxl" );
              desc6.putUnitDouble( idPstn, idPxl, position );
              var idOrnt = charIDToTypeID( "Ornt" );
              var idOrnt = charIDToTypeID( "Ornt" );
              var idHrzn = charIDToTypeID( "Hrzn" );
              desc6.putEnumerated( idOrnt, idOrnt, idHrzn );
          var idGd = charIDToTypeID( "Gd  " );
          desc5.putObject( idNw, idGd, desc6 );
      executeAction( idMk, desc5, DialogModes.NO );      
      };//end function horG
  
function placeResizeOn(){
// =======================================================
    var idsetd = charIDToTypeID( "setd" );
        var desc6 = new ActionDescriptor();
        var idnull = charIDToTypeID( "null" );
            var ref1 = new ActionReference();
            var idPrpr = charIDToTypeID( "Prpr" );
            var idGnrP = charIDToTypeID( "GnrP" );
            ref1.putProperty( idPrpr, idGnrP );
            var idcapp = charIDToTypeID( "capp" );
            var idOrdn = charIDToTypeID( "Ordn" );
            var idTrgt = charIDToTypeID( "Trgt" );
            ref1.putEnumerated( idcapp, idOrdn, idTrgt );
        desc6.putReference( idnull, ref1 );
        var idT = charIDToTypeID( "T   " );
            var desc7 = new ActionDescriptor();
            var idextensionsOn = stringIDToTypeID( "extensionsOn" );
            desc7.putBoolean( idextensionsOn, false );
            var idresizePastePlace = stringIDToTypeID( "resizePastePlace" );
            desc7.putBoolean( idresizePastePlace, true );
            var idmodernFreeTransform = stringIDToTypeID( "modernFreeTransform" );
            desc7.putBoolean( idmodernFreeTransform, true );
        var idGnrP = charIDToTypeID( "GnrP" );
        desc6.putObject( idT, idGnrP, desc7 );
    executeAction( idsetd, desc6, DialogModes.NO );
    }

function placeOverlay(file){
// =======================================================
    var idPlc = charIDToTypeID( "Plc " );
        var desc371 = new ActionDescriptor();
        var idIdnt = charIDToTypeID( "Idnt" );
        desc371.putInteger( idIdnt, 2 );
        var idnull = charIDToTypeID( "null" );
        desc371.putPath( idnull, new File( file ) );
        var idFTcs = charIDToTypeID( "FTcs" );
        var idQCSt = charIDToTypeID( "QCSt" );
        var idQcsa = charIDToTypeID( "Qcsa" );
        desc371.putEnumerated( idFTcs, idQCSt, idQcsa );
        var idOfst = charIDToTypeID( "Ofst" );
            var desc372 = new ActionDescriptor();
            var idHrzn = charIDToTypeID( "Hrzn" );
            var idPxl = charIDToTypeID( "#Pxl" );
            desc372.putUnitDouble( idHrzn, idPxl, 0.000000 );
            var idVrtc = charIDToTypeID( "Vrtc" );
            var idPxl = charIDToTypeID( "#Pxl" );
            desc372.putUnitDouble( idVrtc, idPxl, -0.000000 );
        var idOfst = charIDToTypeID( "Ofst" );
        desc371.putObject( idOfst, idOfst, desc372 );
    executeAction( idPlc, desc371, DialogModes.NO );    
    }

function blendIf(){
// =======================================================
    var idsetd = charIDToTypeID( "setd" );
        var desc376 = new ActionDescriptor();
        var idnull = charIDToTypeID( "null" );
            var ref3 = new ActionReference();
            var idLyr = charIDToTypeID( "Lyr " );
            var idOrdn = charIDToTypeID( "Ordn" );
            var idTrgt = charIDToTypeID( "Trgt" );
            ref3.putEnumerated( idLyr, idOrdn, idTrgt );
        desc376.putReference( idnull, ref3 );
        var idT = charIDToTypeID( "T   " );
            var desc377 = new ActionDescriptor();
            var idBlnd = charIDToTypeID( "Blnd" );
                var list3 = new ActionList();
                    var desc378 = new ActionDescriptor();
                    var idChnl = charIDToTypeID( "Chnl" );
                        var ref4 = new ActionReference();
                        var idChnl = charIDToTypeID( "Chnl" );
                        var idChnl = charIDToTypeID( "Chnl" );
                        var idGry = charIDToTypeID( "Gry " );
                        ref4.putEnumerated( idChnl, idChnl, idGry );
                    desc378.putReference( idChnl, ref4 );
                    var idSrcB = charIDToTypeID( "SrcB" );
                    desc378.putInteger( idSrcB, 0 );
                    var idSrcl = charIDToTypeID( "Srcl" );
                    desc378.putInteger( idSrcl, 0 );
                    var idSrcW = charIDToTypeID( "SrcW" );
                    desc378.putInteger( idSrcW, 198 );
                    var idSrcm = charIDToTypeID( "Srcm" );
                    desc378.putInteger( idSrcm, 209 );
                    var idDstB = charIDToTypeID( "DstB" );
                    desc378.putInteger( idDstB, 0 );
                    var idDstl = charIDToTypeID( "Dstl" );
                    desc378.putInteger( idDstl, 0 );
                    var idDstW = charIDToTypeID( "DstW" );
                    desc378.putInteger( idDstW, 255 );
                    var idDstt = charIDToTypeID( "Dstt" );
                    desc378.putInteger( idDstt, 255 );
                var idBlnd = charIDToTypeID( "Blnd" );
                list3.putObject( idBlnd, desc378 );
            desc377.putList( idBlnd, list3 );
            var idLefx = charIDToTypeID( "Lefx" );
                var desc379 = new ActionDescriptor();
                var idScl = charIDToTypeID( "Scl " );
                var idPrc = charIDToTypeID( "#Prc" );
                desc379.putUnitDouble( idScl, idPrc, 416.666667 );
            var idLefx = charIDToTypeID( "Lefx" );
            desc377.putObject( idLefx, idLefx, desc379 );
        var idLyr = charIDToTypeID( "Lyr " );
        desc376.putObject( idT, idLyr, desc377 );
    executeAction( idsetd, desc376, DialogModes.NO );    
    }

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 01, 2021 Oct 01, 2021

Copy link to clipboard

Copied

Could you share some file your script works with?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 01, 2021 Oct 01, 2021

Copy link to clipboard

Copied

I think 병규김63647638 will have to share them, since they're not mine to share.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 01, 2021 Oct 01, 2021

Copy link to clipboard

Copied

I'm not interested in his images, just one that would work with script...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 01, 2021 Oct 01, 2021

Copy link to clipboard

Copied

Here's one you can test on the 5X7 selection. As mention above, you have to create a folder on your desktop called Portrait crop overlays and name this file 5x7cm.jpg5x7cm.jpg

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 02, 2021 Oct 02, 2021

Copy link to clipboard

Copied

It works now. Thank You!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 02, 2021 Oct 02, 2021

Copy link to clipboard

Copied

This is so perfect for me. I pay my respect to you. I'm so thankful. I don't know how to repay you.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 28, 2021 Sep 28, 2021

Copy link to clipboard

Copied

There are a lot of lines on those images. Do you really need them? You want just enough to see the relation to the size of the head to the frame of the crop. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 28, 2021 Sep 28, 2021

Copy link to clipboard

Copied

All of the OP originals  un-cropped images seem to be shot with nearly the exact  same camera setup. The same focal length the same distance to the subject.   All are portrait images the big difference is the subjects are different. Some are tall some are short and some  in between.   All subjects seem to have average size heads and all image seem to be full frontal portraits.  So in these Image all heads  are approximately the same size. However, the position of the heads differ in each portrait image.  So if a Script can select/detect the head in these portrait images it could set a 4:5  portrait selection relative to the Head's location.  Then crop the image to that portrait and size the crop image to print 8"x10" resmples at some ppi you want to print at.  I believe the script  the Jazz-y poster in this forum  could be modified to do this.  However I would need some of the OP un-croped portrait image to test with.  

 

I tried with portraits  where heads in the portrait varied in size.  Close but no cigar.  However the camera set up are not the same the  portraits images have different perspectives for the distance to subject differed and the focal length lens could also have been used.

image.png

JJMack

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 28, 2021 Sep 28, 2021

Copy link to clipboard

Copied

Yes, I need those things. I'm a photographer.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 16, 2021 Sep 16, 2021

Copy link to clipboard

Copied

Wow, chuck, this seems so useful! I never understood why the crop tool does not offer an overlay for the requirements of the US or European ID pictures...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 10, 2022 Jul 10, 2022

Copy link to clipboard

Copied

Chuck,

 This script is EXACTLY what I've been searching for, but doesn't seem to work in Photoshop 2022. It certainly could be my fault as I've never use the script feature. Attached is the error I'm seeing. Would you mind advising me on what I should do? Many thanks!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 10, 2022 Jul 10, 2022

Copy link to clipboard

Copied

@danielo11729583 are you using the exact sript that I posted earlier? I did a search for the term desc41, as shown in your error message, but it didn't find anything. If the script has been modified, can you post it?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 12, 2022 Jul 12, 2022

Copy link to clipboard

Copied

I haven't modified the script in any way. I copied and pasted the script into a TextEdit (Mac) document, converted to plain text, saved, changed file type to .js and then browsed within Photoshop and opened it. Perhaps this method is not the way to go about creating a script, but this is my first time. Thanks!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 12, 2022 Jul 12, 2022

Copy link to clipboard

Copied

That's odd. Sound like you copied it properly, but I would use a jsx extension rather than just js.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 12, 2022 Jul 12, 2022

Copy link to clipboard

Copied

LATEST

Changing to jsx fixed it. Thanks!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 10, 2020 May 10, 2020

Copy link to clipboard

Copied

We recently exchanged on a similar thread regarding croping and resizing a bunch of images of various sizes and even resolution… Scripts could work but we found also some interesting native solutions. You should have look at this to get insights…Fashion e-commerce AutoSelect Subject and Crop

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 16, 2021 Sep 16, 2021

Copy link to clipboard

Copied

There also was a thread recently in which @jazz-y managed to use Liquify in a Script to locate faces with a Script. 

Crop/trim image automation 3:4

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 27, 2021 Sep 27, 2021

Copy link to clipboard

Copied

Jazz-z posted a script not too long ago where he basically used  a liquify mesh he had  that he use with liquify  to select  the head in a portrait image.    You should be able to modify that script to be able to set a 4:5 aspect ration portrait selection. To crop your portrait images to approximately the same size 8" x 10"  Portrait where all heads will be about the same size and located in the same image area.  I would use the modified script in an action that would resize the 4:5 crop image to be 8" x 10" at the ppi you want.  The action could also be made interactive where  you could reposition the position of the Crop selection the modified script sets so you can tweak  portrait  selected before the action crop the image and resizes to 8" x 10".   

Something like:

 image.png

 

You show all your original portraits are near the sane size and all seem to be shot by the sane camera and setup.  You would need to modify the script to sett and appropriate 4:5 selection for your original image.    I downloaded some random portrait from the web.  They all were croped 8"x10" however the portrait composition varies  because the camera set up and  portrait compositions varied greatly as did the image sizes.

Capture.jpg

JJMack

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines