Ass Parade Oem Adobe Photoshop Elements free gay clips Bangbros Big Ass Buy Accutane No Prescription Canadian Pharmacy Online Buy Generic Accutane Oem Adobe Photoshop Elements Download CorelDRAW Graphics Suite BANGBROS bisexual porn brandi belle brandi belle
Lodge Photo Home Browse photos | License photos | Buy prints | Shopping Cart | Clients | Blog | Contact Mathew | Join e-mail list
Home > Travel and photo blog


Photoshop scripting with Javascript

I do almost all of my image processing using Adobe Photoshop CS3, in common with just about every other photographer on the planet. Much of this is automated using Photoshop Actions, which are a way to record and playback a sequence of Photoshop commands. In other programs such as Microsoft Word or Excel, these are called macros.

Actions are a way of automating Photoshop processes that are performed frequently, but they have one fundamental limitation: there is no way for an action to evaluate some condition and do something different based on the result.

For example, a Photoshop action might downsize an image by 10%. Using the Batch feature of Photoshop, you could apply that action to all images in a folder. However, if you want to downsize only those images in the folder that are larger than, say, 3072 pixels on the longest side, actions and batching can’t help you. There’s no way for an action to evaluate a condition like “longest side < 3072 pixels”. This is where scripting comes in — you can write a small program (the script), that interacts with Photoshop to perform more complex tasks. Although it might not sound like it, scripting is a form of programming. There is no getting around the fact that you have to learn something about how to write programs to use scripting, and this is its disadvantage compared to Actions.

Photoshop has been “scriptable” since version 7, but scripting support has gotten much better in the last two releases. You can use AppleScript, Microsoft Visual Basic, or Javascript. Some people like to get into language “wars of religion” — I will say only this: Javascript is the only language that works across PC, Mac or UNIX, and this is a good reason for preferring it, but my primary motivation was efficiency. I chose Javascript because I had learned to program in C and Java in a “previous life”. Despite its name, Javascript has very little in common with Java, but both Java and Javascript have very similar syntax to the languages C and C++.

If you are going to do any Photoshop scripting, there are two very helpful PDF documents you need to read. Fortunately, they are installed on your hard drive by the Photoshop installer. The Photoshop Scripting Guide and the Javascript Reference Guide are both in \Program Files\Adobe\Adobe Photoshop CS3\Scripting Guide (at least on my system). The purpose of this article is not to re-hash the contents of those documents, but to provide an example that you can pick apart to figure out how to write your own scripts.

An example script: saving image metadata as XMP files

Another use for scripting is around Photoshop commands that cannot be recorded as actions. There aren’t many of these, but some manipulations of image metadata cannot be recorded. Metadata (literally, “data about data”) are things like the caption, keywords, title and other information about an image. It is accessed through the “File Info…” option of the File menu in Photoshop. This data is stored as an XML document inside of the image file by Photoshop. The particular XML that Photoshop stores is called XMP, and you can save, load and append .xmp files to images using the Advanced panel of the File Info dialog box. The problem is that you can’t record saving and loading XMP files in an action. I wanted to use the XMP data in another program to automate keyword display on my web site, so I ended up writing a Javascript program to automate this function.

The code below scans a folder full of JPEG files and outputs the XMP file for any image that has metadata associated with it. It is commented, and in conjunction with the documents from Adobe, you ought to be able to understand how the program works, and perhaps adapt it to your own needs. This code is provided free, and purely for its educational value. Enjoy!


// Output xmp.js
// (c) Copyright 2004 Mathew Lodge
// Rev 2, 02-Mar-2004
//
// This script prompts the user for an input directory, which contains JPEG source images.
// It outputs one .xmp metadata file per image, unless the file has no XMP metadata.     

// Uncomment the next line to show the debugger
$.level = 1; debugger;     

// Save current dialog preferences
var startDisplayDialogs = app.displayDialogs;     

// Don’t display dialogs
app.displayDialogs = DialogModes.NO;     

// Constants
var FILE_TYPE = “.jpg”; // The type of files that this script works on — you can change
var SEARCH_MASK = “*” + FILE_TYPE; // Image file filter to find only those files
var XMP_TYPE = “.xmp”; // File extension for XMP output files
var MAC_XMP_TYPE = “XMPT”; // Macintosh file type for .xmp files
var MAC_XMP_CREATOR = “8BIM”; // Macintosh file creator for .xmp files     

// Set of exception strings for error handling
var X_NOINPUT = “noInput”;
var X_BADDOC = “badDoc”;
var X_WERROR = “writeError”;
var X_CERROR = “closeError”;     

try {
	// Ask user for input folder
	var inputFolder = Folder.selectDialog(”Select a folder to process”);
	if (inputFolder == null)
		throw X_NOINPUT;     

    // get all files in the input folder
	var fileList = inputFolder.getFiles(SEARCH_MASK);     

	// Open each file in turn
	for (var i = 0; i < fileList.length; i++) {
	    // Only want to open non-hidden files (and no folders)
		if ((fileList[i] instanceof File) && (fileList[i].hidden == false)) {
			// Open the file in Photoshop
			var docRef = open(fileList[i]);
			if (docRef == null)
				throw X_BADDOC;     

			if (docRef.xmpMetadata != null) {
				// Document has XMP metadata, so process it
				var inFileName = fileList[i].name; // Filename without path
				// Replace the file’s current extension (e.g. .jpg) with .xmp
				var outFileName = inFileName.toLowerCase(); // Output file is lower case
				outFileName = outFileName.replace(FILE_TYPE, XMP_TYPE); // Make .xmp
				var outputXMP = new File(inputFolder + “/” + outFileName);
				// Open file for writing. Mac type and creator are ignored on other systems
				var success = outputXMP.open(”w”, MAC_XMP_TYPE, MAC_XMP_CREATOR);
				if (!success)
					throw X_WERROR;     

				// Write out the meta data
				success = outputXMP.writeln(docRef.xmpMetadata.rawData);
				if (!success)
					throw X_WERROR;     

				// Close the file
				success = outputXMP.close();
				if (!success)
					throw X_CERROR;
			}
			// Close the Photoshop file
			docRef.close(SaveOptions.DONOTSAVECHANGES);
		}
    }
}
catch (exception) {
	// Show degbug message and then quit
	alert(exception);
}
finally {
	// Reset app preferences
	app.displayDialogs = startDisplayDialogs;
}

Tags: , , ,

Leave a Reply


Bang bros BangBros Bang pass fetishhits hot brunette free gay clips gay porn movies busty brunette busty brunette horny brunette horny brunette brunette sex brunette sex brunette fucking brunette fucking brunette babe brunette babe sexy brunette sexy brunette naked brunette naked brunette brunette celebrity cream pie brunette anal beautiful brunette brunette teen brunette teen brunette pussy brunette pussy brunette pic brunette lesbian young brunette brunette milf cute brunette cute brunette porn tube brunette petite brunette petite brunette brunette blow job baitbus bait bus brunette slut gorgeous brunette hot brunette lesbian big tit brunette evanrivers evan rivers nude brunette mature brunette mature brunette brunette cum shot brunette cum shot milfsoup pretty brunette brunette milf