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

Batch process photos, each to specific size using data file

Community Beginner ,
Apr 29, 2020 Apr 29, 2020

Copy link to clipboard

Copied

Hey Folks,

 

I have about 550 images that all need to be resized to various specific product sizes. I have an excel file that has a column that corresponds to each image file name, a column for Height dimension and a column for Width dimension. Is there a way to use batch image processing to resize each photo based on the data file dimensions? I really hoped that Image Processor had a way to just import a data file. Is there a plug-in that might perform this function?

 

Thanks!

 

Chris

TOPICS
Actions and scripting , Windows

Views

2.8K

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 3 Correct answers

Community Expert , Apr 29, 2020 Apr 29, 2020

Another option would be a batch two-step approach:

 

1) Batch import the width and and or height values against an unused metadata placeholder field.

 

file info.png

 

2) A simple script could use one or both of the metadata field variables to resize the active document, which can then be batch processed (File > Automate > Batch). You will need to record the script into an action, the script can be installed or simply referenced from an absolute path.

 

 

 

/*
Resize Doc from Metadata Placeholders.jsx
Batch 
...

Votes

Translate

Translate
Community Expert , Apr 30, 2020 Apr 30, 2020

My quick code posting missed this vital clue, I assumed that we were both on the same page regarding Photoshop:

 

 

#target photoshop

 

 

As you were initially posting a question in the Photoshop forum! The metadata scripts being Bridge based probably derailed you!

 

Install this into your application/program folder for Photoshop ... /Presets/Scripts

 

https://prepression.blogspot.com/2017/11/downloading-and-installing-adobe-scripts.html

 

I have changed the code to remove this metadata after re

...

Votes

Translate

Translate
Community Beginner , May 14, 2020 May 14, 2020

Thanks Steven! I finally got this to work properly. There are a few more steps I did to get this all to work so I'm going to list them here for anyone else that is looking to try this.

 

After I loaded the JavaScript into the Photoshop Scripts Folder in the Program Files Folder I recorded an Action in Photoshop just executing this script on 1 of the files and called it "Image Resizer Action". Then I went back to Bridge > Tools > Photoshop > Image Processor and used these options: (1) 550 images ar

...

Votes

Translate

Translate
Adobe
Community Expert ,
Apr 29, 2020 Apr 29, 2020

Copy link to clipboard

Copied

You could script that. You need to design in a some process that handle aspect ratio mismatches well like crop the image to the desired output  aspect ratio and then resizing the image  to the desired out put size.  However, that will not work well if the aspect ratio mismatch is large.  If you crop a landscape aspect ration image into a portrait image or a portrait to landscape the cropped imaged composition will not be acceptable.   The Image processor  resize is a  constrained resize.   Image aspect ratios will not change.  If the images aspect ratio is wrong then out put images  will be smaller then  the output image size desired 

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 ,
Apr 29, 2020 Apr 29, 2020

Copy link to clipboard

Copied

Another option would be a batch two-step approach:

 

1) Batch import the width and and or height values against an unused metadata placeholder field.

 

file info.png

 

2) A simple script could use one or both of the metadata field variables to resize the active document, which can then be batch processed (File > Automate > Batch). You will need to record the script into an action, the script can be installed or simply referenced from an absolute path.

 

 

 

/*
Resize Doc from Metadata Placeholders.jsx
Batch process photos, each to specific size using data file
https://community.adobe.com/t5/photoshop/batch-process-photos-each-to-specific-size-using-data-file/m-p/11092247
*/

/* Capture original rulers */
var origRulerUnits = app.preferences.rulerUnits;

/* Set rulers to px */
app.preferences.rulerUnits = Units.PIXELS;

/* photoshop:Credit = "Credit Line" - metadata placeholder field for width */
var metaWidth = app.activeDocument.info.credit;

/* Convert value to integer */
var newWidth = parseInt(metaWidth);

/* photoshop:Source = "Source" metadata placeholder field for height */
var metaHeight = app.activeDocument.info.source;

/* Convert value to integer */
var newHeight = parseInt(metaHeight);

/* Resize */
app.activeDocument.resizeImage(newWidth, newHeight, null, ResampleMethod.BICUBIC);

/* Call function to delete Photoshop File Info */
//deleteFileInfo();

/* Reset rulers */
app.preferences.rulerUnits = origRulerUnits;

/* Function to delete Photoshop File Info */
function deleteFileInfo() {
    if (ExternalObject.AdobeXMPScript === undefined) ExternalObject.AdobeXMPScript = new ExternalObject("lib:AdobeXMPScript");
    var xmp = new XMPMeta(activeDocument.xmpMetadata.rawData);
    xmp.deleteProperty(XMPConst.NS_PHOTOSHOP, "Source");
    xmp.deleteProperty(XMPConst.NS_PHOTOSHOP, "Credit");
    app.activeDocument.xmpMetadata.rawData = xmp.serialize();
}

 

 

 

Getting the spreadsheet values into the correct file as metadata is easy as there are many existing tools for this task (ExifTool or Bridge scripts).

 

This would be my approach as I could do that in a few minutes, creating a more complex script would take a lot more time and knowledge than I have.

 

JJMack makes good points regarding aspect ratio, he is obviously assuming that the final aspect ratio may or may not match the input 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 Beginner ,
Apr 30, 2020 Apr 30, 2020

Copy link to clipboard

Copied

Thanks to both of you for you assistance with this. All of the files are cropped tight to the product image and all have different aspect ratios, orientations, and sizes. They will keep the same aspect ratio upon shrinking them. Stephen, I think you are on the right track with this solution. I'm not experienced with coding at all, so this will definetly be a learning experience for me. 

 

So, I was able to get all the Metadata imported through Bridge. I had to make modifications of the metadata fields based on the import tool that I decided to use which was the Metadatadeluxe.com script. I had to change the Height to the Instructions field and Source as the Width to cooincide with their header template. I changed that in the script below.

 

/* Resize Doc from Metadata Placeholders.jsx
Batch process photos, each to specific size using data file
https://community.adobe.com/t5/photoshop/batch-process-photos-each-to-specific-size-using-data-file/m-p/11092247 */

/* Capture original rulers */
var origRulerUnits = app.preferences.rulerUnits;

/* Set rulers to px */
app.preferences.rulerUnits = Units.PIXELS;

/* photoshop:Source = "Source" - metadata placeholder field for width */
var metaWidth = app.activeDocument.info.source;

/* Convert value to integer */
var newWidth = parseInt(metaWidth);

/* photoshop:Instructions = "Instructions" metadata placeholder field for height */
var metaHeight = app.activeDocument.info.instructions;

/* Convert value to integer */
var newHeight = parseInt(metaHeight);

/* Resize */
app.activeDocument.resizeImage(newWidth, newHeight, null, ResampleMethod.BICUBIC);

/* Call function to delete Photoshop File Info */
//deleteFileInfo();

/* Reset rulers */
app.preferences.rulerUnits = origRulerUnits;

/* Function to delete Photoshop File Info */
function deleteFileInfo() {
    if (ExternalObject.AdobeXMPScript === undefined) ExternalObject.AdobeXMPScript = new ExternalObject("lib:AdobeXMPScript");
    var xmp = new XMPMeta(activeDocument.xmpMetadata.rawData);
    xmp.deleteProperty(XMPConst.NS_PHOTOSHOP, "Credit");
    xmp.deleteProperty(XMPConst.NS_PHOTOSHOP, "Instructions");
    app.activeDocument.xmpMetadata.rawData = xmp.serialize();
}

 

I just created the .jsx using the script above, but I got back an error message from Bridge. I did some reading on the Adobe Photoshop Script Guide and I can't find out what the issue is.

Error.png

I am using CC2019. I can update to the newest version, but I'll have to get my IT department to do that as they have restrictions on runing executable files.

 

Thanks again for all your help and hopefully I can get this worked out.

 

Cheers!

 

Chris

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 ,
Apr 30, 2020 Apr 30, 2020

Copy link to clipboard

Copied

My quick code posting missed this vital clue, I assumed that we were both on the same page regarding Photoshop:

 

 

#target photoshop

 

 

As you were initially posting a question in the Photoshop forum! The metadata scripts being Bridge based probably derailed you!

 

Install this into your application/program folder for Photoshop ... /Presets/Scripts

 

https://prepression.blogspot.com/2017/11/downloading-and-installing-adobe-scripts.html

 

I have changed the code to remove this metadata after resizing using your new fields:

 

 

/* Resize Doc from Metadata Placeholders.jsx
Batch process photos, each to specific size using data file
https://community.adobe.com/t5/photoshop/batch-process-photos-each-to-specific-size-using-data-file/m-p/11092247 */

#target photoshop

/* Capture original rulers */
var origRulerUnits = app.preferences.rulerUnits;

/* Set rulers to px */
app.preferences.rulerUnits = Units.PIXELS;

/* photoshop:Source = "Source" - metadata placeholder field for width */
var metaWidth = app.activeDocument.info.source;

/* Convert value to integer */
var newWidth = parseInt(metaWidth);

/* photoshop:Instructions = "Instructions" metadata placeholder field for height */
var metaHeight = app.activeDocument.info.instructions;

/* Convert value to integer */
var newHeight = parseInt(metaHeight);

/* Resize */
app.activeDocument.resizeImage(newWidth, newHeight, null, ResampleMethod.BICUBIC);

/* Call function to delete Photoshop File Info */
//deleteFileInfo();

/* Reset rulers */
app.preferences.rulerUnits = origRulerUnits;

/* Function to delete Photoshop File Info */
function deleteFileInfo() {
    if (ExternalObject.AdobeXMPScript === undefined) ExternalObject.AdobeXMPScript = new ExternalObject("lib:AdobeXMPScript");
    var xmp = new XMPMeta(activeDocument.xmpMetadata.rawData);
    xmp.deleteProperty(XMPConst.NS_PHOTOSHOP, "Credit");
    xmp.deleteProperty(XMPConst.NS_PHOTOSHOP, "Instructions");
    app.activeDocument.xmpMetadata.rawData = xmp.serialize();
}

 

 

To remove the metadata placeholders after resizing, uncomment this line by removing the // characters:

 

 

//deleteFileInfo();

 

 

To this:

 

 

deleteFileInfo();

 

 

P.S. You could just import one field, either the width or the height, then change the resize line to:

 

 

app.activeDocument.resizeImage(newWidth, null, null, ResampleMethod.BICUBIC);

 

 

In this case, removing the newHeight variable reference and replacing it with null

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 ,
May 14, 2020 May 14, 2020

Copy link to clipboard

Copied

LATEST

Thanks Steven! I finally got this to work properly. There are a few more steps I did to get this all to work so I'm going to list them here for anyone else that is looking to try this.

 

After I loaded the JavaScript into the Photoshop Scripts Folder in the Program Files Folder I recorded an Action in Photoshop just executing this script on 1 of the files and called it "Image Resizer Action". Then I went back to Bridge > Tools > Photoshop > Image Processor and used these options: (1) 550 images are pulled in through Bridge (2) I chose to Save in "Same Location" (3) "Save as JPEG" and unchecked the "Resize to Fit" option (4) Run Action: Defult Action, Image Resizer Action and I clicked RUN at the top.

 

It took a few minutes but all of the images resized based on the metadata and were loaded into a folder called JPEG within my existing folder!!!

 

Thanks again for all your help!

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