Skip to main content
Participating Frequently
August 23, 2012
Question

Looking for a script that will size photos down and give unique filenames

  • August 23, 2012
  • 2 replies
  • 1855 views

Here's the challenge:

I have a bunch of photos that need to be sized down to three different types of thumbnails, each group of thumbnails needs to have a specific prefix to the filename while keeping the rest of filename in tact.

So example:

I start out with a photo 1400 x 933

That photo needs to be sized down to 3 different smaller sizes: 630 x 420, 210 x 140 and 140 x93 (all of those have the same aspect ratio as 1400 x 933). So far this is a simple Action in Photoshop.

The trick I can't figure out is that these photos need to have a specific file naming convention. Say for example the 1400 x 933 photo we start out with is named w_paul_001.jpg the other photos once sized down need to be: x_paul_001.jpg (for the 630x420), y_paul_001.jpg (for the 210 x 140) and z_paul_001.jpg (for the 140x93).

How I do dat?

This topic has been closed for replies.

2 replies

JJMack
Community Expert
Community Expert
August 23, 2012

Russell Brown's web site download and install Image Processor Pro plug-in script one run just using it dialog should do it. Needs CS5 or CS6 I beleive... Will handle any image file format RAW, Layered PSD or Tiff, Jpg png etc including mixtures of file types and can save just about any supported output file format.

JJMack
Inspiring
August 23, 2012

The mad old scientist of scripting! Eh. Yes, image process 1..2...3 is available for ye olde versions of PS

in the archive section

http://www.russellbrown.com/scripts_archive.html

Participating Frequently
August 24, 2012

Yeah, I"m running CS5 too, so that russellbrown.com site doesn't seem to work since it's CS4....

Inspiring
August 23, 2012

This will do what you want:

var srcDoc = app.activeDocument;

var imgNum = srcDoc.name.substring(7, (srcDoc.name.length)-4);

var myJpgQuality = 12

var sizeArray = [

[1400, 933, "x_paul_"],

[630,  420, "y_paul_"],

[100,  100, "z_paul_"]

]

for (var i=0; i<sizeArray.length; i++)

{

  var shrinkWidth =  sizeArray [0];

  var shrinkHeight = sizeArray [1];

  var mySaveName = sizeArray [2];

  var id428 = charIDToTypeID( "Dplc" );

  var desc92 = new ActionDescriptor();

  var id429 = charIDToTypeID( "null" );

  var ref27 = new ActionReference();

  var id430 = charIDToTypeID( "Dcmn" );

  var id431 = charIDToTypeID( "Ordn" );

  var id432 = charIDToTypeID( "Frst" );

  ref27.putEnumerated( id430, id431, id432 );

  desc92.putReference( id429, ref27 );

  var id433 = charIDToTypeID( "Nm  " );

  desc92.putString( id433, mySaveName );

  executeAction( id428, desc92, DialogModes.NO );

  activeDocument.resizeImage(shrinkWidth, shrinkHeight, 72, ResampleMethod.BICUBIC);

  filePath = srcDoc.path + '/' + mySaveName + imgNum + '.jpg';

  var jpgFile = new File(filePath);

  jpgSaveOptions = new JPEGSaveOptions();

  jpgSaveOptions.formatOptions = FormatOptions.OPTIMIZEDBASELINE;

  jpgSaveOptions.embedColorProfile = true;

  jpgSaveOptions.matte = MatteType.NONE;

  jpgSaveOptions.quality = myJpgQuality;

  activeDocument.saveAs(jpgFile, jpgSaveOptions, true, Extension.LOWERCASE);

  app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);

}

Participating Frequently
August 24, 2012

Thanks for sending this, really appreciate it. I"m guessing I"m doing something wrong. I put the suffix .jsx at the end of the file, calling it  CROPS.jsx

I set it to happen when you close the document, but when I close the document in hopes to run the script I"m getting the following error:

Error 1302: No such element

Line: 1

- > var srcDoc = app.activeDocument;

Do I need to save it in a specific folder? I just have it on my desktop. Not sure what I"m doing wrong and how to get it to work. Sorry for being such a novice here. Much appreciated with any help.

Thanks!

Participating Frequently
August 24, 2012

Man, we are soooo close. The crops are working but the filenaming is still a bit off. It's putting in the b_, m_ and t_.... but it's not keeping everything after the underscore.

So for example, if I start with my file f_08162012_015_paul.jpg the other files need to be:

b_08242012_paul.jpg

m_08242012_paul.jpg

t_08242012_paul.jpg

But they're coming out looking like:

b_012_015_paul.jpg

m_012_015_paul.jpg

t_012_015_paul.jpg

I mean, we're so close. What are we missing here?


Ghoulfool!! You rule!!!

It worked!!

The problem was in this area:

var srcDoc = app.activeDocument;

var imgNum = srcDoc.name.substring(7, (srcDoc.name.length)-4);

var myJpgQuality = 12

I just changed it to:

(2,

This way it keeps the m_ or t_ or b_ and the rest of the filename remains the same.

I really apprecaite your help in this one!