Skip navigation
paulslater3
Currently Being Moderated

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

Aug 23, 2012 5:21 AM

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?

 
Replies
  • Currently Being Moderated
    Aug 23, 2012 6:26 AM   in reply to paulslater3

    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 [i][0];
      var shrinkHeight = sizeArray [i][1];
      var mySaveName = sizeArray [i][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);
    }
    
     
    |
    Mark as:
  • JJMack
    3,425 posts
    Jan 9, 2006
    Currently Being Moderated
    Aug 23, 2012 8:36 AM   in reply to paulslater3

    http://forums.adobe.com/servlet/JiveServlet/downloadImage/2-4613514-221819/450-380/IPPRO.jpgRussell 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.

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 23, 2012 9:23 AM   in reply to JJMack

    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

     
    |
    Mark as:
  • JJMack
    3,425 posts
    Jan 9, 2006
    Currently Being Moderated
    Aug 23, 2012 8:58 PM   in reply to paulslater3

    paulslater3 wrote:

     

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

    What????http://russellbrown.com/scripts.html

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 24, 2012 1:25 AM   in reply to paulslater3

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 24, 2012 9:01 AM   in reply to paulslater3

    I don't have any problems. What have you got the rulers set to? If it was "percent", that could explain the enlarged files.

     

    You might want to add

    
    app.preferences.rulerUnits = Units.PIXELS;
    
    

    at the start of the script. I left it out as I was in a hurry and always set unit size to pixels

    You've probably already done it, but change sizeArray to

     

    var sizeArray = [
    [630, 420, "b_"],
    [210, 140, "m_"],
    [140, 93,  "t_"]
    ]
    
     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points