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

Automate resize and croping .

New Here ,
Oct 07, 2020 Oct 07, 2020

Copy link to clipboard

Copied

I am a graphic designer in a e-commerce site and need to resize and crop hundreds of images daily.

I am trying to design a action that can identify the model and crop the image with aspect ratio of 5-7 as shown in image below.sample.jpg

TOPICS
Actions and scripting

Views

598

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

correct answers 1 Correct answer

Community Expert , Oct 07, 2020 Oct 07, 2020

Try this. Of course, it all depends on how well select subject actually selects the model:

 

#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 doc = activeDocument;

selSub ();
var cropBounds = doc.selection.bounds;
var vertLength = parseInt(cropBounds[3]-cropBounds[1]);
var horLength = parseInt(cropBounds[2]-cropBounds[0]);
var cRatio = 5/7;
var horPad
...

Votes

Translate

Translate
Adobe
Community Expert ,
Oct 07, 2020 Oct 07, 2020

Copy link to clipboard

Copied

Hi you can only create a action to resize or such function no identify is possible this is artificial intelligence which you are asking...regards

Ali Sajjad / Graphic Design Trainer / Freelancer / Adobe Certified Professional

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 ,
Oct 07, 2020 Oct 07, 2020

Copy link to clipboard

Copied

yes you are right but Photoshop already have select subject but when i crop with that it doesn't crop with aspect ratio.

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 07, 2020 Oct 07, 2020

Copy link to clipboard

Copied

Have you looked at: File > Scripts > Image Processor ?

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 ,
Oct 07, 2020 Oct 07, 2020

Copy link to clipboard

Copied

Image processer can resize the image but can't crop 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
Community Expert ,
Oct 07, 2020 Oct 07, 2020

Copy link to clipboard

Copied

Hello, you should post a  thread on the https://feedback.photoshop.com site, watched by Adobe staff. Make sure to provide as many relevant details as possible as what your needs are (is there always a person, could the subject be an object, etc...

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 07, 2020 Oct 07, 2020

Copy link to clipboard

Copied

Using select subject isn't a bad idea, providing that it selects properly. What you have to do is write. Script that takes the bounds of that selection and adds the padding you want around the model, and crops to the 5X7 ratio. 

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 ,
Oct 07, 2020 Oct 07, 2020

Copy link to clipboard

Copied

The issue is i don't want any extra space on top and bottom only on sides if there is any way to extend selection only vertically it can work

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 07, 2020 Oct 07, 2020

Copy link to clipboard

Copied

Only when select subject selection bounds has a 5:7 or narrower aspect ratio.  A wider subject would be cropped if resized to 5" x 7". For you would do a Image crop to remove content above and below the subject in the document then set the document resolution for the image to be 7"  high.  Next you would set the canvas width to 5"  wide subject would be cropped and narrow subject would have boarder added.

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
Community Expert ,
Oct 07, 2020 Oct 07, 2020

Copy link to clipboard

Copied

A script can check the select subject bounds and if wider then 5:7 resized to 5" wide the add  boarder above an below the subject so you have your 5"x7" all images will most likely have boarders.  Only 5:7 subject will not have boarders. 

 

Adding additional logic the boarder areas could be the content of the image areas that was cropped off. The logic could be complex if the subject is close to any canvas edge.

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
Community Expert ,
Oct 07, 2020 Oct 07, 2020

Copy link to clipboard

Copied

If you don't want any space, then you would still take the selection bounds, then add the proper dimension for the width, to get the 5X7 ratio.

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 07, 2020 Oct 07, 2020

Copy link to clipboard

Copied

Try this. Of course, it all depends on how well select subject actually selects the model:

 

#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 doc = activeDocument;

selSub ();
var cropBounds = doc.selection.bounds;
var vertLength = parseInt(cropBounds[3]-cropBounds[1]);
var horLength = parseInt(cropBounds[2]-cropBounds[0]);
var cRatio = 5/7;
var horPad = ((vertLength*cRatio) - horLength)/2;

doc.selection.deselect();

cropImg ();

app.preferences.rulerUnits = oldPref;


function selSub(){
    var idautoCutout = stringIDToTypeID( "autoCutout" );
        var desc4 = new ActionDescriptor();
        var idsampleAllLayers = stringIDToTypeID( "sampleAllLayers" );
        desc4.putBoolean( idsampleAllLayers, false );
    executeAction( idautoCutout, desc4, DialogModes.NO );    
    };

function cropImg(){
      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]-horPad );
              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]+horPad );
          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 );   
    };

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 ,
Oct 07, 2020 Oct 07, 2020

Copy link to clipboard

Copied

Amazing brother you fixed a huge problem for us thanks alot man thanks alot

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 07, 2020 Oct 07, 2020

Copy link to clipboard

Copied

To Chuck script after the crop step  I added  the following  to set the size in inches.

 

 

 

 

app.preferences.rulerUnits = Units.INCHES;
doc.resizeImage(5);

 

 

 

The script will mess up if subject aspect ratio is wide.

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
Community Expert ,
Oct 07, 2020 Oct 07, 2020

Copy link to clipboard

Copied

LATEST

Capture.jpg

#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 doc = activeDocument;

selSub ();
var cropBounds = doc.selection.bounds;
var vertLength = parseInt(cropBounds[3]-cropBounds[1]);
var horLength = parseInt(cropBounds[2]-cropBounds[0]);
 
if (horLength/vertLength<=5/7) {
	var cRatio = 5/7;
	var horPad = ((vertLength*cRatio) - horLength)/2;

	doc.selection.deselect();

	cropImg ();
	app.preferences.rulerUnits = Units.INCHES;
	doc.resizeImage(5);
} else alert("subject too wide");

app.preferences.rulerUnits = oldPref;


function selSub(){
    var idautoCutout = stringIDToTypeID( "autoCutout" );
        var desc4 = new ActionDescriptor();
        var idsampleAllLayers = stringIDToTypeID( "sampleAllLayers" );
        desc4.putBoolean( idsampleAllLayers, false );
    executeAction( idautoCutout, desc4, DialogModes.NO );    
    };

function cropImg(){
      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]-horPad );
              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]+horPad );
          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 );   
    };
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