Applying our Photoshop Thumbnail Script to Multiple Documents
Posted on May 25, 2009 by Chadwick Wood
A reader asked if there was a way to apply the Photoshop Thumbnail script I wrote to all open documents, so I figured I'd post it up here for everyone to see. All it takes is a small addition and modification, to iterate through all of Photoshop's open documents, instead of just the active one. Here's the code, with comments:
// docs is a reference to the Documents collection, that holds all open documents
docs = app.documents;
for (i=0; i < docs.length; i++) {
// instead of getting the active document, iterate through each open doc
doc = docs.index(i);
// the rest of the script is unchanged
doc.changeMode(ChangeMode.RGB);
var thumbDim = 60; // the dimension of the square
// crop to a big square, conditionally, based on dimensions
if (doc.height > doc.width) {
doc.resizeCanvas(doc.width,doc.width,AnchorPosition.TOPCENTER);
}
else {
doc.resizeCanvas(doc.height,doc.height,AnchorPosition.MIDDLECENTER);
}
// resize, then auto-contrast and sharpen
// specify that our units are in pixels, via creation of a UnitValue object
doc.resizeImage(UnitValue(thumbDim,"px"),null,null,ResampleMethod.BICUBIC);
doc.activeLayer.autoContrast();
doc.activeLayer.applySharpen();
// our web export options
var options = new ExportOptionsSaveForWeb();
options.quality = 70;
options.format = SaveDocumentType.JPEG;
options.optimized = true;
var newName = 'thumb-'+doc.name+'.jpg';
doc.exportDocument(File(doc.path+'/'+newName),ExportType.SAVEFORWEB,options);
}
Tags:
Comments
Hello,
First I want to say thanks for these scripts, they are so useful! My questions pertains to the usage model for this multiple-document thumbnail generation.
Is there a way, either with this script or some other, that I could batch-process a large amount of files like this that are not necessarily open documents? What I am envisioning is a way to open photoshop-->batch process and make a whole directory full of thumbails without having to have all the originals open at all. In this way the user could process a huge amount of files very quickly and with minimal memory usage.
Does something like that exist? I tried fiddling with the various options in the Batch Processor but I couldn't figure out how to make use of the javascript routines that you've provided. Perhaps they need to be tied to an "action"?
Thanks,
Dave
Hi Dave,
Actually, I've never really thought that Photoshop was good for doing large batches of images, as it's way too slow and memory-heavy, as you said. I wrote another article about how you can batch process images using Ruby and ImageMagick, but that is admittedly more of a developer-oriented solution. You can use those two technologies (or PHP or some other scripting language instead of Ruby) to do pretty much whatever kind of batch image processing you want to, but the learning curve is steeper.
I've had half a mind to develop a web-based application that lets you upload batches of images and then use a web-based interface to construct a batch process on those images, and download the result. And maybe you could save "presets" of batch processes that you have to regularly. And then I'd charge some small price per batch, based on size (I think). Would you be interested in something like that? Just curious.
Thanks, I'll check out the Ruby/ImageMagick article. PERL/PHP scripting is right up my alley.
Personally, I don't think I would be interested in a pay-per-use solution -- but that's just my opinion.
Dave
Hi!
This is great stuff! But in CS3 I get an error here: doc = docs.index(i);
Saying: error 1302 element does not exist.
Please help.
Regards
The other script for individual images works well. But solving this would be great.
Hey tronics, I'm actually still using CS2, so I've never tested this script (or others) on CS3. If and when I get a copy of CS3, I'll update my scripts!
Is there a way for a php script to take an uploaded file, then open it in photoshop, then manipulate it (say changing the hues), then saving it in a folder.
so in other words, if a user on a website uploads an image and wants it to be black and white instead of color, is there a script that will automatically do that? Thanks
I don't think that's possible using Photoshop, but it is possible using ImageMagick to do the image manipulation (e.g. color -> black/white).
This post I wrote about using PHP and ImageMagick might put you on the right track.
Thanks Chadwick, i dont think that would work though cause I would need it to do certain things that only Photoshop can do. (like apply certain filters)
Ah, well, if you need Photoshop-specific features, from a web server setting, then no, I don't know of a way to do that, sorry.
Great script. A few changes...
To work with CS3 you need to change doc = docs.index(i); to doc = docs[i];
You also need to immediately set the current document as the active document with app.activeDocument = doc;
Hope that's useful.
MikeA,
Your changes also work on Photoshop CS4. Thanks for posting these!
Dave
Mike's changes make it work in CS5 as well. Thanks for the great post! The Photoshop scripting API looks very capable.
Add new comment