Welcome to Omgili,
Omgili ( Oh My God I Love It ;) is a search engine for discussions. With Omgili you can find answers and solutions, debates, discussions, personal experiences, opinions and more... To learn more about Omgili click here.
This is a complete preview of the discussion as it was indexed by Omgili crawlers. Use this preview if the original discussion is unavailable.
Click here to view the original discussion.
[http://forums.dpreview.com/forums/readflat.asp?message=29334885&changemo...]
Click here to search for discussions with Omgili discussions search engine.
 |
Need help with a script/batch process: Retouching Forum: Digital Photography Review
I have almost 200 photos which have been geotagged, thus the lat/long data is now in the exif info.
I need to create/find a script that can pull the lat/long data and overlay it in text over the bottom of the photo.
I've never had any experience with scripts in photoshop;
Is this possible, and if so, how difficult?
Any help or guidance you can provide would be greatly appreciated.
Thanks,
TKH
|
 |
I really don't know Photoshop Scripting or javescript but am not afraid to hack at others scripts.
Have fixed some and bent others to do what I want.
I only do Javescript Scripts because the are platform independent.
With CS3 come two PDF files you will need.
I think in "C:\Program Files\Adobe\Adobe Photoshop CS3\Scripting Guide namely "Photoshop CS3 Scripting Guide.pdf and "Photoshop CS3 JavaScript Ref.pdf" also you may want to look into "Adobe ExtendScript Toolkit 2" and the Photoshop plug-in the 'Script Listener"
Here are two Script I downloaded and fixed.
The first one sets and retrieves a document meta-data.
I don't know where you have stored the PGS data.
This script may be helpful the second creates a text layer with some EXIF data and some XMP Lens data.
Actions are easy you can add canvas and position the text layer in the expanded canvas area.
orient.jsx
//
// Copyright 2002-2003.
Adobe Systems, Incorporated.
All rights reserved.
// This scripts demonstrates how to rotate a layer 90 degrees clockwise.
// Original file came from PSCS scripting\samples\javascript\RotateLayer.js
//
// Variation Copyright(c)Douglas Cody, 2004, All Rights Reserved.
// http://www.clikphoto.com
//
// This script will look at the document orientation (portrait vs landscape)
// On the first execution, if the document is a portrait, it will be rotated
// to a horizontal.
On the second execution, a rotated document will be
// restored to a vertical.
This effectively toggles the orientation ONLY if
// the original document started out as a portrait.
NOTE!!! the field,
// File->FileInfo...->Origin->Instructions is modified to hold an interim
// state.
//
// Bug Fixes by JJMack, 2008, with the original code Square images were always
// rotated -90 and marked "rotate back" with two executions you wound up with
// an upside down image...
The original code would also fail to rotate an image
// back if the action added canvas and change the rotated images aspect ratio
// to other then landscape.
Again you wind up with a marked upside down image.
// In addition units the compare could fail because the script did not set the
// units to use for rulers.
//
// Warning: If you use this script in your own actions there are a few rules you
// should follow.
You should not do anything between the two executions of the
// script that could change the document Canvas size so it no longer has a
// Landscape Aspect ratio.
That also means No stops to give the user Photoshop
// control.
No interactive steps that could change the documents orientation
// like Image size, Canvas size, Canvas rotation, no cropping etc between the
// two executions.
//
// The Action itself can crop rotate etc as long as it knows what it is doing
// and is sure the document will have a landscape orientation the second time
// the script is run.
For non marked images that have a portrait aspect ratio
// will be rotated and marked.
//
////alert ("Caution: This action modifies the FileInfo Instructions field!");
if (app.documents.length >
0) {
if (app.activeDocument.info.instructions == "rotate back"){
app.activeDocument.rotateCanvas(90.0);
app.activeDocument.info.instructions = " ";
////alert( " 90 roate");
}
else {
// Set the ruler units to PIXELS
var orig_ruler_units = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
// alert( " Width = " + app.activeDocument.width + " Height = " + app.activeDocument.height );
if (app.activeDocument.width <
App.activeDocument.height) {
app.activeDocument.rotateCanvas(-90.0);
app.activeDocument.info.instructions = "rotate back";
////alert( app.activeDocument.info.instructions + " -90 roate");
}
// Reset units to original settings
app.preferences.rulerUnits = orig_ruler_units;
}
}
else { alert("You must have at least one open document to run this script!");
}
|
 |
StampExif.jsx
// This script was hacked from one I downloaded from the web JJMack 2008
/* Script to stamp copyright and camera data of shot */
// This script is supplied as is.
It is provided as freeware.
// The author accepts no liability for any problems arising from its use.
// enable double-clicking from Mac Finder or Windows Explorer
#target photoshop // this command only works in Photoshop CS2 and higher
// bring application forward for double-click events
app.bringToFront();
// ensure at least one document open
if (!documents.length) {
alert('There are no documents open.', 'No Document');
}
// if at least one document exists, then proceed
else {
main();
}
// main - main function
function main() {
/* Null business owner */
var Biz = "";
var Owner = "";
/* Variables You can hard code your business owner here */
var Biz = "Mouseprints";
var Owner = "John J McAssey";
/* sizeFactor influences text size 1 will use largest font 2 will half that font size */
var sizeFactor = 1;
/* textX and TextY positions text placement 0 and 0 Top Left corner of image in pixels */
var textX = 0;
var textY = 0;
/* Internal Photoshop Text name */
var fontName = "ArialMT";
var fontName = "TimesNewRomanPSMT";
var fontName = "Tahoma";
/* Text Color */
textColor = new SolidColor;
textColor.rgb.red = 255;
textColor.rgb.green = 255;
textColor.rgb.blue = 255;
/* END Variables You can hard code your business owner here */
// remember users Ruler avd Type Units and set ours
var strtRulerUnits = app.preferences.rulerUnits;
var strtTypeUnits = app.preferences.typeUnits;
app.preferences.rulerUnits = Units.PIXELS;
app.preferences.typeUnits = TypeUnits.PIXELS;
/* Trying to figure out font size for the number of lines to cover the document height */
/* and getting setting text area to cover the document was a trip.
Adobe Postscript trip */
/* I believe that 72 or 72.27 Point/Pica Size Photoshop Preference maybe I should see if */
/* I could retrieve it.
Anyway mine is set to 72 Setting the document resolution taking */
/* the document width and dividing by 72 would probably yield number of characters that */
/* would fit in the document width.
Setting the documents resolution comes into play */
/* with Photoshop text support.
Using the documents height and dividing the by the number */
/* of lines of text I needed I hoped would yield the font size I needed.
However that */
/* did not work the text area was correct the number of text lines did not fit.
I needed */
/* to use a smaller font.
When the document resolution is set to 72 DPI and I set a text */
/* layer font size to 72 and the text area the number of pixels I want and observing */
/* Photoshop's text options bar there I see a one 1 to one relationship.
72 px = 72 px. */
/* If I set the documents resolution lower and set a Photoshop text layer font size to */
/* 72 px I see Photoshop scale the number to a lower number of pixels in the option bar.
*/
/* Just what I needed.
Setting the Documents resolution to 60 DPI let the number of line */
/* I needed fit on the document.
However Photoshop also scaled the text area I set down */
/* in size and that number of lines did not fit within that area.
I needed to scale the */
/* text area up.
Scaling the Text area up using 72/resolution did the trick...
*/
var testres = 60;
res = app.activeDocument.resolution;
if(res!=testres){ app.activeDocument.resizeImage(app.activeDocument.width.value,app.activeDocument.height.value,testres);
}
/* Define var to be used to avoid undefined */
var expTime ="";
var expPgm = "";
var expCmp = "";
var mtrMode = "";
var flshCode = "";
var flshMode = "";
var focLength = "";
var Fstop = "";
var ISO = "";
var Model = "";
var CameraModel = "";
var Artist = "";
var maxF = "";
var wbMode = "";
var phoTime = "";
var picYr = "";
var lens = "";
var cpyrt = "";
var docName = app.activeDocument.name;
/* END var to be used to avoid undefined */
try { // get active document
var doc = app.activeDocument;
}
catch (e){
alert("No Document Open..." );
}
var exifInfo = "";
try {
// alert( "doc.info.exif=" + doc.info.exif );
var numExifItems = doc.info.exif.length;
// alert( "numExifItems=" + numExifItems );
for (var i = 0;
I < doc.info.exif.length;
I++){
exifInfo = exifInfo + doc.info.exif[i][0] + " = " + doc.info.exif[i][1] + "\r";
--
JJMack
|
 |
/* Extracting Data I want to Stamp formated */
checkThisItem(doc.info.exif[i][0], doc.info.exif[i][1])
key=doc.info.exif[i][0];
keyData=doc.info.exif[i][1];
if (key == "Artist") {
// alert ("Key=" + key + " Data=" + keyData );
Artist =("By " + keyData + " ");
}
if (key == "Date Time Original") {
// alert ("Key=" + key + " Data=" + keyData );
var phoTime = keyData;
var dateArray1 = phoTime.split(" ", 2);
phoTime = dateArray1[0];
phoHour = dateArray1[1];
var dateArray2 = phoTime.split(":");
var monthsArray = ["January","February","March","April","May","June","July","August","September","October","November","December"];
phoTime = monthsArray[dateArray2[1]-1]+" " + dateArray2[2]+ ", " + dateArray2[0] +" @ " + phoHour;
var picYr = dateArray2[0];
}
if (key == "Model") {
// alert ("Key=" + key + " Data=" + keyData );
Model = (keyData + " ");
}
if (key == "Max Aperture Value") {
// alert ("Key=" + key + " Data=" + keyData );
maxF = ("maxF " + keyData + " ");
}
if (key == "Focal Length") {
// alert ("Key=" + key + " Data=" + keyData );
focLength = ("@ " +keyData + " ");
}
if (key == "Exposure Program") {
// alert ("Key=" + key + " Data=" + keyData );
expPgm = (keyData + " ");
}
if (key == "Exposure Bias Value") {
// alert ("Key=" + key + " Data=" + keyData );
expCmp = ("Bias " + keyData + " ");
}
if (key == "Metering Mode") {
//alert ("Key=" + key + " Data=" + keyData );
mtrMode = (keyData + " Metering ");
}
if (key == "White Balance") {
// alert ("Key=" + key + " Data=" + keyData );
wbMode = ("White Balance " + keyData + " ");
}
if (key == "ISO Speed Ratings") {
// alert ("Key=" + key + " Data=" + keyData );
ISO = ("ISO " + keyData + " ");
}
if (key == "Exposure Time") {
// alert ("Key=" + key + " Data=" + keyData );
expTime = ("Tv " + keyData + " ");
}
if (key == "F-Stop") {
//alert ("Key=" + key + " Data=" + keyData );
Fstop = ("Av " + keyData + " ");
}
if (key == "Flash") {
// alert ("Key=" + key + " Data=" + keyData );
var flshCode = keyData;
var flshMode = "Flash Code=" + flshCode + " ";
if(flshCode==9){var flshMode = "Firing Flash ";}
if(flshCode==16){var flshMode = "without Flash ";}
}
/* Copyright Year(s) */
var thisYr, toDay
var toDay = new Date();
var thisYr = toDay.getYear() + 1900;
if(picYr!="" && thisYr!=""){ var cpyrt = picYr + "-" + thisYr + " ";}
if(picYr=="" && thisYr!=""){ var cpyrt = thisYr + " ";}
if(picYr==thisYr){ var cpyrt = thisYr + " ";}
/* For cameras that don't set Artist or set unknown in the Exif substitute Owner if set */
if(Artist=="" && Owner!=""){var Artist = "By " + Owner + " ";}
if(Artist=="By unknown " && Owner!=""){var Artist = "By " + Owner + " ";}
/* Lens info */
xml = app.activeDocument.xmpMetadata.rawData;
lensOffset = xml.indexOf("") + "".length;
if(lensOffset >
0) {
lens = xml.substr(lensOffset, xml.length - lensOffset);
lens = lens.substr(0,lens.indexOf(""));
}
/* Hack for my cameras with fixed lens */
if(lens=="" && Model=="E990 "){var lens = "9-28mm";}
if(lens=="" && Model=="E-20,E-20N,E-20P "){var lens = "9-36mm";}
if(lens=="" && Model=="E-10 "){var lens = "9-36mm";}
if(lens=="" && Model=="Canon PowerShot SD700 IS "){var lens = "5.8-23.2mm";}
if(lens!=""){var lens = lens + " ";}
/* Hack for my ultra compact cameras program mode not recorded */
if(Model=="Canon PowerShot SD700 IS "){var expPgm = "Ultra Compact Camera ";}
/* END Extracting Data I want to Stamp formated
|
 |
}
}
catch (e){
alert("No EXIF data exists..." );
}
if ( exifInfo == "" ) {
alert( "No EXIF data exists..." );
}
else {
// alert( "exifInfo=" + exifInfo );
text_layer = doc.artLayers.add();
// Add a Layer
text_layer.name = "EXIF Stamp";
// Name Layer
text_layer.kind = LayerKind.TEXT;
// Make Layer a Text Layer
text_layer.textItem.color = textColor;
// set text layer color
/* Do not set TextType to Pargarph Text for StampEXIF so action can position text layer
text_layer.textItem.kind = TextType.PARAGRAPHTEXT;
// Set text layers text type
*/
text_layer.textItem.font = fontName;
// set text font
text_layer.blendMode = BlendMode.NORMAL // blend mode
text_layer.textItem.fauxBold = false;
// Bold
text_layer.textItem.fauxItalic = false;
// Italic
text_layer.textItem.underline = UnderlineType.UNDERLINEOFF;
// Underlibn
text_layer.textItem.capitalization = TextCase.NORMAL;
// Case
text_layer.textItem.antiAliasMethod = AntiAlias.SHARP;
// antiAlias
// var fontSize = Math.round((doc.height- textY) / ((numExifItems +1) * sizeFactor));
// Calulate font size to use Item nomber + last \r
/* Calulate font size to use for StampExit keep size same for landscape and portrait base on document size */
if (doc.width >= doc.height) {var fontSize = Math.round(doc.height / (30 * sizeFactor));}
else {var fontSize = Math.round(doc.width / (30 * sizeFactor));}
if (fontSize<10){fontSize=10};
// don't use Font size smaller then 10
text_layer.textItem.size = fontSize;
// set text font Size
// text_layer.textItem.position = Array(textX, textY );
// set text layers position in and down
text_layer.textItem.position = Array(textX, (textY + fontSize ));
// set text layers position in and down for Stamp add in fontsize
textWidth = ((doc.width - textX) * 72/testres );
// Text width document width - offset
textHeight = ((doc.height - textY) * 72/testres );
// Text height document height - offset
/* Do not set Text Area for StampEXIF so action can position text layer
text_layer.textItem.width = textWidth;
// set text area width
text_layer.textItem.height = textHeight;
// set text area height
*/
/*
alert(
"res=" + res + " sizeFactor=" + sizeFactor + " numExifItems=" + numExifItems
+ "\r" + "fontsize=" + fontSize + " font=" +fontName
+ "\r" + "Image area width=" + doc.width + " height=" + doc.height
+ "\r" + "text area width=" + textWidth + " height=" + textHeight
+ "\r" + "Text Position top left=" + textX + "," + textY
+ " bottom right=" + (textX + textWidth )+ "," + (textY + textHeight )
);
*/
/*
try{
text_layer.textItem.contents = exifInfo;
}
catch (er) {
alert("Error Setting Contents...");
}
*/
/* Data Stamp format */
text_layer.textItem.contents = "Picture " + docName + " Copyright \u00A9 " + Biz + " " + cpyrt
+ "\r" + Artist + phoTime
+ "\r" + Model + lens + maxF + focLength
+ "\r" + expPgm + expCmp + mtrMode
+ "\r" + wbMode + ISO + expTime + Fstop + flshMode;
}
if(res != testres){ app.activeDocument.resizeImage(app.activeDocument.width.value,app.activeDocument.height.value,res);
}
app.preferences.rulerUnits = strtRulerUnits;
app.preferences.typeUnits = strtTypeUnits;
}
// END - main function
function checkThisItem(key, keyData) {
// alert("Key=" + key + " Data=" + keyData );
}
|
 |
Wow, thank you. I'll play with it and give it a try.
I appreciate the help.
Thanks again,
TKH
|
|
|
|