Extract Lens Data from EXIF

Upload Photoshop Scripts, download Photoshop Scripts, Discussion and Support of Photoshop Scripts

Moderators: xbytor, DavideBarranca, Paul MR

DCK9

Extract Lens Data from EXIF

Postby DCK9 » Thu May 18, 2006 12:22 pm

I am using Regit Youngs Photoshop script (based on Shaun Ivory original) for adding a border & exif data to a JPG.

RY's version adds the lens data, which I like, BUT, the D2H does not seem to handle the EXIF data in the same format. Or maybe it is CS2?

For instance, in RY's script, he is able to "read" the focal length and use this snippet to get lens data (note: focLength is WITH the 1.5x mag):

Code: Select allif(focLength=="127"){
          var Lens = "Nikkor 85mm 1:1.4";
        }

However, I have to change it to this snippet to have CS2 read the lens data correctly (focLength WITHOUT 1.5x and adding "mm"):

Code: Select allif(focLength=="300.0 mm"){
          var Lens = "Nikon 300mm f4 AF-S";
        }

Here is the challenge:

For a Nikon 12-24mm he uses:

Code: Select allif(focLength>=18 && focLength<=36){
          var Lens = "Nikon 12-24mm";
        }

How do I modify this so I can have the script pick up when I am using my Nikon 80-200mm f2.8? I cannot (I dont think) use the numbers since it needs the "mm" to correctly read the info - thus eliminating the use of greater than/lessor than.

Can anyone help?

Thanks in advance.

--- orig RY script here ---

Code: Select all//---------
displayDialogs = DialogModes.NO;
var defaultRulerUnits = preferences.rulerUnits;
preferences.rulerUnits = Units.PIXELS;

function explodeArray(item,delimiter) {
tempArray=new Array(1);
var Count=0;
var tempString=new String(item);
while (tempString.indexOf(delimiter)>0) {
tempArray=tempString.substr(0,tempString.indexOf(delimiter));

tempString=tempString.substr(tempString.indexOf(delimiter)+1,tempString.length-tempString.indexOf(delimiter)+1);

Count=Count+1
}
tempArray=tempString;
return tempArray;
}

var AD = activeDocument;
var resRatio = AD.resolution/72;

if(resRatio!=1){
AD.resizeImage(AD.width.value,AD.height.value,72);
}

var heightVar = AD.height.value+2;

var black = new SolidColor();
black.rgb.red = black.rgb.green = black.rgb.blue = 0;

var white = new SolidColor();
white.rgb.red = white.rgb.green = white.rgb.blue = 255;

backgroundColor = black;

AD.resizeCanvas(AD.width.value+8,AD.height.value+8,
AnchorPosition.MIDDLECENTER);
AD.resizeCanvas(AD.width.value,AD.height.value+60,AnchorPosition.TOPCENTER);


var exifData = AD.info.exif.toString();
explodeArray(exifData,",");

for(n = 0; n < tempArray.length; n = n + 2 ) {

var stringTemp=tempArray
if(stringTemp.indexOf("Exposure Time")!=-1){
var expTime = tempArray;
}

if(stringTemp.indexOf("Focal Length")!=-1){
var focLength = tempArray;
}

if(stringTemp.indexOf("F-Stop")!=-1){
var aptNum = tempArray;
}

if(stringTemp.indexOf("ISO Speed Ratings")!=-1){
var ISONum = tempArray;
}

//Use this to note the lens use.
//Basically, just calculate the 35mm equi of the lens and plug in the
figure.
//Or simply look at the EXIF info from PS CS
//For zoom, just use a range.

if(focLength>=18 && focLength<=36){
var Lens = "Nikkor 12-24mm 1:4";
}
if(focLength=="42"){
var Lens = "Nikkor 28mm 1:2.0";
}
if(focLength=="82"){
var Lens = "Micro-Nikkor 55mm 1:3.5";
}
if(focLength=="87"){
var Lens = "Noct-Nikkor 58mm 1:1.2";
}
if(focLength=="127"){
var Lens = "Nikkor 85mm 1:1.4";
}
if(focLength=="157"){
var Lens = "UV-Nikkor 105mm 1:1.4.5";
}
if(focLength=="72"){
var Lens = "Macro-Nikkor 65mm 1:4.5";
}


if(stringTemp.indexOf("Date Time Original")!=-1){
var phoTime = tempArray;
var dateArray1 = phoTime.split(" ", 1);
phoTime = dateArray1<0>;
var dateArray2 = phoTime.split(":");
var monthsArray =<"January",[BR> "February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December"];
phoTime = monthsArray-1]+" "+dateArray2<2>+"
"+dateArray2<0>;
}

if(stringTemp.indexOf("Model")!=-1){
var cameraModel = tempArray;
}
}

//change the name here!!!

var nameLayer = AD.artLayers.add();
nameLayer.kind = LayerKind.TEXT;
var TI = nameLayer.textItem;
TI.position = <5,heightVar+16>;
TI.contents = "© Regit Young 2005";
TI.font = "Arial";
TI.size = 14;
TI.color = white;
TI.fauxBold = true;

var infoLayer = AD.artLayers.add();
infoLayer.kind = LayerKind.TEXT;
var TI = infoLayer.textItem;
TI.position = <5,heightVar+30>;

TI.contents = cameraModel+" with "+Lens+" @ "+focLength+"mm (35mm
equiv), "+expTime+", "+aptNum+", ISO: "+ISONum+"\u000DDate photo taken:
"+phoTime;

TI.font = "Arial";
TI.size = 11;
TI.color = white;

AD.flatten();
//-----

User avatar
txuku
Posts: 64
Joined: Thu Jan 01, 1970 12:00 am

Re: Extract Lens Data from EXIF

Postby txuku » Tue Jan 09, 2018 9:09 am

Bonjour !

The exif information can be extracted with the app.activeDocument.info method

Attention information varies depending on the model and brand of the device!
And maybe the version of Photoshop ???
So I use this script to determine the number corresponding to the information I want to extract:

Code: Select all

savedUnits=app.preferences.rulerUnits;
var thisDoc=app.activeDocument;
app.preferences.rulerUnits=Units.PIXELS;

// EXIF_info.jsx
//pour connaitre les numeros des informations exif de son appareil
// numeros a modifier dans la fonction InfoExif() du script Exif_New.jsx

var exif_info="";

for (var e = 0; e < thisDoc.info.exif.length; e++){
try
{
var j = e ;
if ( j<10 )
{
exif_info = exif_info + "N° " + j + " " +thisDoc.info.exif[e][0] + " = " + thisDoc.info.exif[e][1] + "\r";
}
else
{
exif_info = exif_info + "N° " + j + " " +thisDoc.info.exif[e][0] + " = " + thisDoc.info.exif[e][1] + "\r";
}
}
catch (e) {}
}

// alert(thisDoc.info.exif);
text_layer=thisDoc.artLayers.add();
text_layer.kind = LayerKind.TEXT;
textColor = new SolidColor;
textColor.rgb.red = 0;
textColor.rgb.green = 0;
textColor.rgb.blue = 0;
text_layer.textItem.color = textColor;
text_layer.textItem.kind=TextType.PARAGRAPHTEXT;
text_layer.textItem.position = Array(thisDoc.width * 0.05, thisDoc.height * 0.05);
text_layer.textItem.size = 18; //a la place de 4
text_layer.textItem.font = "ArialMT";
text_layer.textItem.width = thisDoc.width * 0.8
text_layer.textItem.height = thisDoc.height * 0.8
text_layer.textItem.contents=exif_info;

// restore preferences
app.preferences.rulerUnits=savedUnits;

Then this other one to write them in a layer on the image:

Code: Select all

/* ATTENTION
Il faut utiliser le script EXIF_info.jsx
pour connaitre les numeros des informations exif de son appareil
numeros a modifier dans la fonction InfoExif() du script Exif_New.jsx
*/

/* pour la version CC se Photoshop newTextLayer.textItem.size ne fonctionne pas
il faut inserer la fonction de textItemSizeCC.jsx

*/

app.displayDialogs = DialogModes.NO;
app.preferences.typeUnits = TypeUnits.POINTS;

var docRef = activeDocument;
var docStartResolution = docRef.resolution;
docRef.resizeImage(undefined, undefined, 92, ); //resolution a 92 pour obtenir les memes tailles

var LesExifs="";


//Pour changer la position du texte il faut modifier les pourcentages hauteur et largeur
var posHoriz = activeDocument.width*(2/100); //je donne un pourcentage de la taille du document
var posVertic = activeDocument.height*(997/1000); //pour la position du texte = a modifier

Opacite = 100; // reglage de la transparence du calque texte ( de 0 a 100 )

if ( activeDocument.width > activeDocument.height )
{
TailleFonte = activeDocument.height*(2/100);
//TailleFonte = 48;
}
else { TailleFonte = activeDocument.width*(2/100); }


monNom = ""; // mettre votre Nom a la place ou bien laisser ""


//le reglage des couleurs des exifs

Rouge = 125;
Vert = 45;
Bleu = 10

InfoExif(LesExifs) //lire Les Exifs
//alert(LesExifs);

RedacTexte() //ecrire Les Exifs

docRef.flatten(); //aplatir

docRef.resizeImage(undefined, undefined, docStartResolution, );//retour a la resolution de depart

function RedacTexte()
{
var textColor = new SolidColor;
textColor.rgb.red = Rouge;
textColor.rgb.green = Vert;
textColor.rgb.blue = Bleu;
textColor.opacity = 10;

var newTextLayer = docRef.artLayers.add();
newTextLayer.kind = LayerKind.TEXT;
newTextLayer.textItem.contents = LesExifs;
newTextLayer.textItem.position = Array(posHoriz, posVertic);
newTextLayer.textItem.size = TailleFonte;
newTextLayer.textItem.color = textColor;
newTextLayer.opacity = Opacite;
}

function InfoExif()
{

LesExifs="";

// valeurs de e = numeros a modifier dans la fonction InfoExif() suivant les resultats du script Exif_New.jsx

var e = 6; //Modele------------> Modele
try {
LesExifs =LesExifs + " " + docRef.info.exif[e][1]; //LesExifs + docRef.info.exif[e][0] + " = " + docRef.info.exif[e][1] + "\r";
}
catch (e) {}

var e = 16; //Vitesse------------> Temps d exposition
try {
LesExifs = LesExifs + " " + docRef.info.exif[e][1]; //LesExifs + docRef.info.exif[e][0] + " = " + docRef.info.exif[e][1] + "\r";
}
catch (e) {}

var e = 17; //Ouverture------------> Ouverture du diaphragme
try {
LesExifs = LesExifs + " " + docRef.info.exif[e][1]; //LesExifs + docRef.info.exif[e][0] + " = " + docRef.info.exif[e][1] + "\r";
}
catch (e) {}

var e = 19; //Iso 17------------> Vitesse ISO
try {
LesExifs = LesExifs + " " + docRef.info.exif[e][1]; //LesExifs + docRef.info.exif[e][0] + " = " + docRef.info.exif[e][1] + "\r";
}
catch (e) {}

var e = 28; //Distance focale ------------> Distance focale
try {
LesExifs = LesExifs + " " + docRef.info.exif[e][1]; //LesExifs + docRef.info.exif[e][0] + " = " + docRef.info.exif[e][1] + "\r";
}
catch (e) {}

var e = 21; //Date------------> Date et heure de l original
try {
LesExifs = LesExifs + " " + docRef.info.exif[e][1]; //LesExifs + docRef.info.exif[e][0] + " = " + docRef.info.exif[e][1] + "\r";
}

catch (e) { alert( "ici");}

return LesExifs;

}


Return to “Photoshop Scripts”

Who is online

Users browsing this forum: No registered users and 3 guests