home

cs2 + cs3 save for web

introduction

In Photoshop CS3, CS2 (and earlier versions) you can't automatically save an image to a specific size for web use. You can do this manually via "save for web", and the "optimize to file size" feature there, but you can't automate that in an action. The reason is that the "save for web" action which is recorded has a "quality" value specified, not a target size.

The scripts here provide this "save to target size" feature for CS2 and CS3.

what the scripts do

You can't tell programmatically what size the file will be on disk unless you actually save it. So the scripts first save the file to the target location at 100% quality, then check how big the resultant file is. If the file's too big, the quality is reduced in steps of 10 down to 0, and the file repeatedly saved until the size is small enough or 0 quality is reached. The "keyless" scripts will overwrite output files without prompting and are for "unattended" use, such as within an action. The other script is interactive and prompts for parameters etc.

caveats/limitations

There's no restriction on what you do with this, other than that it's free and used at your own risk. Note that the "keyless" script will overwrite a jpeg file without prompts.

installing the scripts

Download the script (eg right click it and select "save target as", be sure to save it with the extension "jsx").

Save the script wherever photoshop puts scripts on your system. On an XP machine for CS2 it could be: C:\Program Files\Adobe\Adobe Photoshop CS2\Presets\Scripts; on Vista with CS3 something like C:\Program Files\Adobe\Adobe Photoshop CS3\Presets\Scripts

using the scripts

The idea is that you run these scripts as part of an action, although they'll work directly too. Once the script's installed you'll need to restart PS/CS2 or 3, and then you can run the script from: File -> Scripts ->. Alternatively you can put the script somewhere else and access it from: File -> Scripts -> browse without any restart.

within an action

To make it easier to use, record an action with the script in it. Probably the first part of the action would fit the file to the required output size, then change the profile to sRGB. The next step could be to smart sharpen the file (with a dialog so you can tune it). Finally record this script into the action to export the result. Then assign the action to a key combination and you're away.

modifications

You can easily change the step size within the scripts: just edit the file (in Adobe's debugger or notepad). Smaller step sizes give more accuracy on the target size but take longer.

The "keyless" script has a hard coded"output path" - your desktop, and hard coded target size; both can easily be changed.

In the "keyless" script, to save to the same directory as the file was opened from requires the replacement of one line with:

var targetName = docRef.path + "/" +docRef.name.match( /[^.]+/) +".jpg";

This will do the job, but be careful as if you put this in it'll overwrite the original file if the source file was also a jpeg.