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

Photoshop Script - Put Label on Image

Community Beginner ,
Jun 26, 2017 Jun 26, 2017

Copy link to clipboard

Copied

I was wondering if there is a way to create a script that will put a visible label on a group of images.

I have a set of files with a specific serial number name (X100.psd, x101.psd, etc.) that are large color images with a lot of layers. Each of these images has a layer on it relative to the image size (13 percent) named "label." I have a bunch of labels generated as pdf files that have the same name as the image file (X100.pdf, X101.pdf, etx.).

What I would like to do is have the script open the psd file, get the relative dimensions of the label layer and then merge the matching pdf file into the image and then save the newly combined files as a psd with the original name, preferably in a folder different than the original.

TOPICS
Actions and scripting

Views

2.5K

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 , Jun 28, 2017 Jun 28, 2017

The can be done to get an Idea of how to do that look are my PlaceWatermark.jsx It scale a layer and positions it bottom Right.

You need to get the layer bounds to get its current size and get the document size  capitulate the size you want the layer to be transform it and align it to the botton left. You should also make sure the layer is on top of the layer stack so it is not hidden by other layer over it in the stack.

#target photoshop; 

app.bringToFront(); 

var logoFile = "~/Desktop/JJMack.png

...

Votes

Translate

Translate
Adobe
Community Expert ,
Jun 26, 2017 Jun 26, 2017

Copy link to clipboard

Copied

Do you know JavaScript, VSB or Applescript? Do uou have a programming background? If so here is where you can find Adobe Photoshop Scripting documentation Adobe Photoshop Scripting | Adobe Developer Connection

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 Beginner ,
Jun 27, 2017 Jun 27, 2017

Copy link to clipboard

Copied

I am not actually very experienced with scripting at all. I dug and dug and found a script that is pretty darn close, below:

#target photoshop

var inputFolderA = Folder.selectDialog("Please select ImageA folder"); 

var inputFolderB = Folder.selectDialog("Please select ImageB folder"); 

var outputFolderE = Folder.selectDialog("Please select output Folder ImageE folder");

var fileList = inputFolderA.getFiles ("*.psd");

var startRulerUnits = preferences.rulerUnits;

preferences.rulerUnits = Units.PIXELS;

for (var a = 0;a<fileList.length;a++){

          var file =fileList;

          var fileB = file.name.replace(/A/,"B");

          fileB = file.name.replace(/psd/,"pdf");

          var doc = open(file);

          var Bimage = File(inputFolderB +"/" + fileB);

          if(Bimage.exists) {

             var b = open(Bimage);

             activeDocument.selection.selectAll();

             activeDocument.selection.copy();

             app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);

             activeDocument.paste();

             app.activeDocument.activeLayer.name = "Label Text";

          }

          var saveFile = File(outputFolderE +"/" +file.name.replace(/A/,"E"));

          SavePSD(saveFile);

          app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);

}

app.preferences.rulerUnits = startRulerUnits;

function SavePSD(saveFile){

psdSaveOptions = new PhotoshopSaveOptions();

psdSaveOptions.embedColorProfile = true;

psdSaveOptions.alphaChannels = true;

activeDocument.saveAs(saveFile, psdSaveOptions, true, Extension.LOWERCASE);

}

However, I am not sure how to do the last two thinsg, anything that would help would be great. I need to scale the new layer "Label text" to the whole size and position that layer at the bottom left part of the image. Do you know how or can point me in the right direction?

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 ,
Jun 27, 2017 Jun 27, 2017

Copy link to clipboard

Copied

The last two thing save save the modified document with the original name into a different fold should be the easy part.   The hard part is designing the process to modify the document.

The script you found seems to open documents with the same name+suffix from two folder  one with suffix A the other suffix B select all in the second document and past it into the first document  then names the layer  "Label Text" and save a PSD into a third folder  with name+suffix E.  If file name+B does not exists file name+E is not created. It does not seem to be what you described you want to do.

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 Beginner ,
Jun 28, 2017 Jun 28, 2017

Copy link to clipboard

Copied

Actually this script does exactly what I wanted it to do, it combines two files with the same name and saves them in a third folder. The last two things weren't literally the last two things in the script, sorry for the confusion. What I was hoping to add was moving the new added layer "Label Text" to the bottom left of the newly combined psd and scale it relative to the doc size. Is there somewhere I can see how that would be accomplished?

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 ,
Jun 28, 2017 Jun 28, 2017

Copy link to clipboard

Copied

The can be done to get an Idea of how to do that look are my PlaceWatermark.jsx It scale a layer and positions it bottom Right.

You need to get the layer bounds to get its current size and get the document size  capitulate the size you want the layer to be transform it and align it to the botton left. You should also make sure the layer is on top of the layer stack so it is not hidden by other layer over it in the stack.

#target photoshop; 

app.bringToFront(); 

var logoFile = "~/Desktop/JJMack.png"; // Watermark file should be large for resize down works better than up

var LogoSize = 10; // percent of document height to resize Watermark to

var LogoMargin = 1;                                         // percent of Document height the Watermark should have as a margin

placeWatermark(logoFile, LogoSize, LogoMargin);             // Place Watermark  into the bottom right of document

function placeWatermark(Image,Size,Margin){ 

  if(!documents.length) return;   // if no document return

  try{ 

  var doc = app.activeDocument; // set Doc object to active document

  app.displayDialogs = DialogModes.NO; // Dialog off

  var strtRulerUnits = app.preferences.rulerUnits; // Save Users ruler units

  var strtTypeUnits = app.preferences.typeUnits; // Save Users Type units

  app.preferences.rulerUnits = Units.PIXELS; // work with pixels

  app.preferences.typeUnits = TypeUnits.PIXELS; // work with pixels

  var fileObj = new File(Image);                 // the passed file

  if(!fileObj.exists){   // If file does not exits tell user

  alert(fileObj.name  + " does not exist!"); 

  return; 

  } 

  placeFile(fileObj); // Place in file the Watermark png file

  activeDocument.activeLayer.resize(100 ,100,AnchorPosition.MIDDLECENTER); // Insure Place did not scale layer 

  var SB = activeDocument.activeLayer.bounds; // get layers bounds

  var layerHeight = SB[3] - SB[1]; // get layers height 

  var resizePercent = (100/layerHeight)*(Size/100*doc.height.value); // Percent to resize by

  activeDocument.activeLayer.resize(resizePercent ,resizePercent,AnchorPosition.MIDDLECENTER);  // Resize width and height by percentage

  SB = activeDocument.activeLayer.bounds; // get resized layers bounds 

  activeDocument.activeLayer.translate(-SB[0].value,-SB[1].value); // Move resized layer to top left canvas corner

  var LayerWidth = (SB[2].value - SB[0].value); 

  var LayerHeight = (SB[3].value - SB[1].value); 

  marginSize = Margin/100*doc.height.value; // move resized watermark into the document lower right corner with some margin

  activeDocument.activeLayer.translate((doc.width.value -marginSize - LayerWidth),( doc.height.value -marginSize - LayerHeight));

  }

  catch(e) { alert(e + ': on line ' + e.line); } // inform user of error 

  finally{ 

  app.preferences.rulerUnits = strtRulerUnits; // Restore user ruler units 

  app.preferences.typeUnits = strtTypeUnits; // Restore user type units   

  }; 

};

function placeFile(placeFile) { 

    var desc21 = new ActionDescriptor(); 

    desc21.putPath( charIDToTypeID('null'), new File(placeFile) ); 

    desc21.putEnumerated( charIDToTypeID('FTcs'), charIDToTypeID('QCSt'), charIDToTypeID('Qcsa') ); 

    var desc22 = new ActionDescriptor(); 

    desc22.putUnitDouble( charIDToTypeID('Hrzn'), charIDToTypeID('#Pxl'), 0.000000 ); 

    desc22.putUnitDouble( charIDToTypeID('Vrtc'), charIDToTypeID('#Pxl'), 0.000000 ); 

    desc21.putObject( charIDToTypeID('Ofst'), charIDToTypeID('Ofst'), desc22 ); 

    executeAction( charIDToTypeID('Plc '), desc21, 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
Community Beginner ,
Jun 28, 2017 Jun 28, 2017

Copy link to clipboard

Copied

This script is amazing JJMack! Thank you so much, it incorporated with mild alterations. The changed script is below:

#target photoshop

//Main script tanks William_Donelson

var inputFolderA = Folder("/Users/shamid/Models/Proc");

//Folder.selectDialog("Please select ImageA folder"); 

var inputFolderB = Folder("/Users/shamid/Models/Labels");

//Folder.selectDialog("Please select ImageB folder"); 

var outputFolderE = Folder("/Users/shamid/Models/Labelled");

//Folder.selectDialog("Please select output Folder ImageE folder");

var fileList = inputFolderA.getFiles ("*.psd");

var startRulerUnits = preferences.rulerUnits;

preferences.rulerUnits = Units.PIXELS;

for (var a = 0;a<fileList.length;a++){

          var file =fileList;

          var fileB = file.name.replace(/A/,"B");

          fileB = file.name.replace(/psd/,"pdf");

          var doc = open(file);

          var Bimage = File(inputFolderB +"/" + fileB);

          if(Bimage.exists) {

             var b = open(Bimage);

             activeDocument.selection.selectAll();

             activeDocument.selection.copy();

             app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);

             activeDocument.paste();

             app.activeDocument.activeLayer.name = "Label Text";

             //below thanks to JJMack

             app.bringToFront();   

                var LogoSize = 10; // percent of document height to resize Watermark to 

                var LogoMargin = 1;                                         // percent of Document height the Watermark should have as a margin 

 

 

                placeWatermark(LogoSize, LogoMargin);             // Place Watermark  into the bottom right of document 

                function placeWatermark(Size,Margin){

                    activeDocument.activeLayer.resize(100 ,100,AnchorPosition.MIDDLECENTER); // Insure Place did not scale layer   

                    var SB = activeDocument.activeLayer.bounds; // get layers bounds  

                    var layerHeight = SB[3] - SB[1]; // get layers height   

                    var resizePercent = (100/layerHeight)*(Size/100*doc.height.value); // Percent to resize by  

                    activeDocument.activeLayer.resize(resizePercent ,resizePercent,AnchorPosition.MIDDLECENTER);  // Resize width and height by percentage  

                    SB = activeDocument.activeLayer.bounds; // get resized layers bounds   

                    activeDocument.activeLayer.translate(-SB[0].value,-SB[1].value); // Move resized layer to top left canvas corner  

                    var LayerWidth = (SB[2].value - SB[0].value);   

                    var LayerHeight = (SB[3].value - SB[1].value);   

                    marginSize = Margin/100*doc.height.value; // move resized watermark into the document lower right corner with some margin 

                    activeDocument.activeLayer.translate((doc.width.value -marginSize - LayerWidth),( doc.height.value -marginSize - LayerHeight)); 

  } 

               

               

            

          }

          var saveFile = File(outputFolderE +"/" +file.name.replace(/A/,"E"));

          SavePSD(saveFile);

          app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);

}

app.preferences.rulerUnits = startRulerUnits;

function SavePSD(saveFile){

psdSaveOptions = new PhotoshopSaveOptions();

psdSaveOptions.embedColorProfile = true;

psdSaveOptions.alphaChannels = true;

activeDocument.saveAs(saveFile, psdSaveOptions, true, Extension.LOWERCASE);

}

I have one last question, how would I change it so that the orientation is bottom left, I seem to only be able to make it on the bottom right?

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 ,
Jun 28, 2017 Jun 28, 2017

Copy link to clipboard

Copied

Study the last transform that moves the layer to the lower right see if you can figure what its doing think top left.

activeDocument.activeLayer.translate

((doc.width.value -marginSize - LayerWidth),( doc.height.value -marginSize - LayerHeight));

maybe

(marginSize,( doc.height.value -marginSize - LayerHeight));

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 Beginner ,
Jun 28, 2017 Jun 28, 2017

Copy link to clipboard

Copied

LATEST

Thank you, thank you, 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