Click on the link at the bottom of the page to return to Lazy Dogg’s Laziness Page.

A JavaScript script for Adobe Photoshop to set image size.

Download the script.

This script is for resizing Photoshop documents without changing the aspect ratio. Suppose you wanted all your images to be 800 pixels by 600, but they were a variety of portrait, landscape, panoramic - all cropped to different sizes. A normal resize would end up squeezing and squashing them all, and they’d look pretty horrible!

Or imagine you’re doing a web gallery or photoblog (which is whay I’m doing, incidentally!) Vertical/horizontal centering of thumbnails in lists is a nightmare for css and cross-browser compatibility, so one easy solution is to make all the thumbnails the same size (eg 80x60). But when they’re starting off at all different shapes and sizes, that’s a time-consuming job. That’s why I wrote this script to do it for me. It’s not exactly elegant, but here’s how to use it:

  1. First, you’ll need to download the script (right-click or control-click (for Mac users) the link below and choose "Save target as" (or similar).
  2. Open the file in a text editor and find the line “var newWidth = 80;”. This is where you can choose how many pixels wide you want your pictures to end up. Choose a number and save the file.
  3. Now find the line “var newRatio = 0.75;”. Use this to choose the height to width ratio that you want your pictures to be. At 0.75, the height is three quarters of the width, so your pictures will have a 4:3 landscape ratio. Set it to 1 and you’ll get square pictures. Set it to 1.3334 for 4:3 portrait (roughly, all you maths pedants!) size.
  4. Save the script, open Photoshop, open a document and run the script (this is somewhere in the File menu: it’s under “Automate” in Photoshop 7). Hey presto (hopefully): the script resizes the canvas (if required) to the aspect ratio you’ve asked for, and then resizes the whole image with your picture in the middle, aspect ratio intact!

So, even if this worked, it’s not saving you much time is it? Aha - here’s where you need to combine some other Photoshop features. First, make an Action that runs your script, then saves and closes the file. Then use Photoshop’s Automate feature to batch-run that Action on lots of files. It will zoom through whole folders full of files, and THAT is a substantial triumph for laziness! Respect!!

Note: I wrote this script in Photoshop CS and found it wasn’t working on Photoshop 7. To fix it, I had to edit the script and change "docRef.width.value" and "docRef.height.value" to "docRef.width" and "docRef.height".