If you have ever had a massive number of images you needed quickly and accurately resized for export, upload to web or any other reason, you may well be familiar with the concept of recording Photoshop Actions. These beautiful little tools allow you to literally record a macro (series of user actions) that can then be applied to the currently active document. Further, when combined with the “bulk” feature of Photoshop, you can apply this action to an entire directory and apply the action to each and every image, exporting the resulting image to a specified location as well. Overall, this is an extremely useful tool and can save minutes — if not hours — of work, but it has one tiny limitation that has been a bane to me for some time. When recording an action, you must specify either a height or a width on resize: there is no way to conditionally apply your length to the height OR width dependent upon ratio. Enter the Photoshop Script.
So, let me take a moment and explain what my first simple script does. My goal was to have a script I could execute on a file that would prompt me for both a length to which the image should be resized as well as a flag for whether or not to use the shortest side of the image for that measurement. By default, I typically resize to the largest dimension. For instance, if I resize a 1000 x 800 pixel image and provide 500 as the resize value, I would expect the resulting dimensions to be 500 x 400 pixels. On the other hand, executing the same script with a value of 600 and selecting the “Use short edge” option would result in a 750 x 500 pixel image. This conditional calculation and resize is why the script is thus named “Smart Resize”.
Needless to say, the script was incredibly simple in scope to write and execute, and after doing a little digging and discovering the proper way to build and display dialog inputs for UI, it was completed. Now, with script in hand, I can create an action that calls this script on each image in my “to export” directory. By recording the action with different values for the script, I can quickly export multiple different sized and optimized images for different usage.
So, why is writing this script even worth considering rather than just using an online tool such as ImageMagick for resizing? Well, if the resizing is done properly via the script, you actually are using Photoshop’s Bicubic (or any other available algorithm) filtering to do the resampling. You don’t need me to tell you just how much better quality your pictures will possess by using this tool for what it was intended.
Feel free to download the script and try it out. If you have questions or recommendations for enhancements, feel free to let me know. To install, simply download, unzip and place into your Adobe/Photoshop/Presets/Scripts/ directory. When you have an image loaded, you simply have to navigate under File -> Scripts -> Browse… and select the Smart Resize file. Enjoy!