Saturday, August 20, 2005

Sloppy Borders In Photoshop Made Easy

In my last post, Photoshop Scripts, I talked a little bit about a Photoshop script I created to automatically add sloppy borders around my images like this:

SloppyExample

This journal entry will be the details of what I did so you too can use my script and produce your own sloppy borders instantly.

Before I go into the process, you may be wondering why I didn’t create a Photoshop action to produce the sloppy border.  While actions are nice, they are limited in power and I couldn’t figure out a way to do it using just Photoshop actions.  That forced me to learn the much more powerful Photoshop Scripting.

The pre-requisite knowledge for you to be able to do this as well is just a limited computer knowledge (how to create directories and edit files) and knowledge of Photoshop.  You really don’t need to know the scripting syntax, but looking at the script should make some sort of sense.  The basic process that the script does is this:

  • Enlarge the canvas of the active image by 10 pixels so that there is some room for the sloppy border
  • Open the sloppy border template and resize it to the exact same size of the image
  • Select all of the border template, copy it
  • Close the sloppy border template
  • Paste the copied sloppy border template on top of the original image
  • flatten the layers

You could do all of those steps by hand and not use a script.  But if you do this often, it becomes pretty tedious and the sloppy border script comes in handy.

Here are the steps to produce your own script and sloppy border. 

(1) Make a directory (also known as a folder) in which to store your sloppy border script and psd file.  The directory name should be sloppy.  The location of the directory needs to be in the /presets/scripts directory where you installed adobe Photoshop.  On my windows system, the full path is:

C:\Program Files\Adobe\Adobe Photoshop CS2\Presets\Scripts\sloppy

(2) you need to design your sloppy border template.  Create a .psd file called Sloppy-1.psd which has the border that you want to outline your photos.  Here is an example of what the file should look like in Photoshop.

SloppyBorder

Basically you have a border around the outside and in the middle you have a deleted region so that there isn’t anything. Save this in the sloppy directory.  My image is about 500 pixels by 300 pixels in size and it seems to work well.  However, I think any sized image (within reason) should work fine. If you want to be lazy, just copy the above image into Photoshop, place a selection around the checker box area and then delete it.

(3) With a text editor, create a sloppy1.js file in the sloppy directory which has the following contents:

var curDoc = app.activeDocument;
curDoc.resizeCanvas(curDoc.width+UnitValue("10 px"),curDoc.height+UnitValue("10 px"));
var sloppyDoc=open(File(app.path+"/presets/scripts/sloppy/sloppy-1.psd"));
sloppyDoc.resizeImage(curDoc.width,curDoc.height);
sloppyDoc.selection.selectAll();
sloppyDoc.selection.copy();
sloppyDoc.close(SaveOptions.DONOTSAVECHANGES);
curDoc.paste();curDoc.mergeVisibleLayers(); 

You can just copy the above 10 lines and paste into the .js file to quickly create your script instead of typing the whole thing.  You may need to adjust and change the 10 px values in the script on line 2  if your border is either larger or smaller than mine to make it work correctly.  You will know when you run your script and see the results.

Your contents of the sloppy directory should be:

SloppyDirectoryImage

(4) Finally, it is time to test your script. Restart Photoshop if it is already active.  Then open an image that you want to put a sloppy border around.  Then select file -> scripts -> sloppy1 to execute the sloppy1 script.    Your photo should have a sloppy border around it.  If the border crops out too much of the picture, adjust the 10 px to something larger in line 2 of the sloppy1.js file.   If there is some gap between the border and your image, decrease the 10px values.  Use trial and error till you get something nice.

Some caveats.  I am new to Photoshop scripting and I haven’t performed extensive testing, so it may not work in all cases.  But feel free to play around with the script and modify it to your liking.   You can easily scale this to other border types by just making a Sloppy-2.psd sloppy2.js (and editing line 3 to point to Sloppy-2.psd) and storing it in the sloppy directory.  And finally, this sloppy border script follows a programming design philosophy of  “do the simplest thing that could possibly work”.  It doesn’t do any advanced calculations that would be required to perfectly fit the border on top of the image. While not perfect, it works well in practice. 

Have fun scripting and if you make any significant changes or improvements to this script that you want to share, please post a comment here so that others can benefit. 

 

2 Comments:

Blogger Jim Cook said...

I have a much improved script. Click the link on the left in "My Other Web Sites" where it says Photoshop Sloppy Border Script to see what it is all about.

9:58 AM  
Blogger Michelle said...

Is it possible to download the sloppy border psd file from your website? I'm not seeing a link. Thanks

2:04 PM  

Post a Comment

<< Home