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
  • 1856 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!

Inspiring
August 24, 2012

paulslater3,

Yup, you've got the script to work, but don't set the action to work upon closing. A bit like wanting to go into a room by closing the door first .

The best thing to do is record the action like this: Open one of the files you want the script to work on. Record an action, from the file menu pick scripts and crops.jsx from the list. This will then perform the script. STOP recording the action. Now you need only call the script from that action, or from a batch file. Incidentally, the files get saved out in the same directory as the inital image. So if your "master" file was in C:\photos\vacation then all the smaller instances will also be in C:\photos\vacation. Hope this helps.