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 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);
}
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.
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!
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.
Thanks again for all the assistance. Although I tried running script again and it's doing something, but not what I want. It's taking a long time to load and it's processing the image.
It's sizing the image to 100800 px x 67176 px
After image processes it gives me an error:
Error 8007: User cancelled the operation
Line: 40
-> activeDocument.saveAs(jgpFile,jpgSaveOptions, true, Extension.LOWERCASE);
Any clues? Thanks in advance!!
Also, looking at your code, I need to auto-size down to the following dimensions and file prefixes, although I see where I can edit that in the code:
b_ (this size should be 630px X 420px)
m_ (this size should be 210px X 140px)
t_ (this size should be 140px X 93px)
The 1400px X 933px size will be manually cropped and I will do the auto-crops with the script to the above sizes and file prefixes.
Hope that's more clear.
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_"]
]
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!
North America
Europe, Middle East and Africa
Asia Pacific