5 Replies Latest reply on Mar 8, 2017 1:50 PM by crooibos

    Script to get Exif data on text layer in PhotoSHop CS4

    Dewcal

      I am trying to find (or learn how to write ) a script that will include certain exif data on a spearate text layer in an open image.  I do not want the full, verbose exif rather soemthing that reads

       

      D3; 70-200 f2.8 @ 89mm; 1/60; f8; ISO 200; Matrix; 0.0 Ev; Apertrure Priority; Flash Y/N

       

      Is there something liek this available?  If not, any (polite) suggestions as to how I write same?  Especially how do I callup the various fields that I require?

       

      Thanks,

      Dave

        • 1. Re: Script to get Exif data on text layer in PhotoSHop CS4
          Michael L Hale Level 5

          There are scripts that place metadata from the documnet into a text layer. I don't know of one that uses those exact fields. You could try modifying one of those or create your own.

           

          If you want to create your own, the doc's metadata can be accessed with app.activeDocument.info , app.activeDocument.info.exif, and app.activeDocument.xmpMetadata.rawData

          1 person found this helpful
          • 2. Re: Script to get Exif data on text layer in PhotoSHop CS4
            Dewcal Level 1

            Michael,

             

            Thanks for response - at least I now know where to start calling the data from.  Do you have a link to any of the scripts that you know of as so far I do not even have one of these!

             

            Many thanks

            Dave

            • 3. Re: Script to get Exif data on text layer in PhotoSHop CS4
              crooibos

              Did you find some script to get your goal? Some EXIF's data over a photo, I mean.

              • 4. Re: Script to get Exif data on text layer in PhotoSHop CS4
                Pedro Cortez Marques Level 3

                I did not try this on CS4, only on CC2017.

                You can get other elements on the exif.

                I had to choose a few.

                 

                trey this on an active image:

                 

                // get and organize the exif data:
                var myExif_arr = activeDocument.info.exif; // or ... activeDocument.info.exif.toSource().split(',');
                var thisImageExifPlusData = "[Exposure ";
                var sizeCR2 = "";
                var ISO = "";
                var focalLength = "";
                var whiteBalance = "";
                var flash = "";
                if (myExif_arr instanceof Array && myExif_arr.length > 0) {
                    for (var e in myExif_arr) {
                        // you can use this above to get all the data available on exif (use ESTK console)
                        // $.writeln(myExif_arr[e].join('\t●'));
                        if (myExif_arr[e][0] == "Exposure Program") {
                            var exposureProgramResult = myExif_arr[e][1].toString().replace(/\s/g,'').toLowerCase();
                            if (exposureProgramResult.match(/defined/) != null) { thisImageExifPlusData += "|pgr>?? "; }
                            else if (exposureProgramResult.match(/manual/) != null) { thisImageExifPlusData += "|pgr>Man "; }
                            else if (exposureProgramResult.match(/normal/) != null) { thisImageExifPlusData += "|pgr>Norm "; }
                            else if (exposureProgramResult.match(/aperture/) != null) { thisImageExifPlusData += "|pgr>AP "; }
                            else if (exposureProgramResult.match(/shutter/) != null) { thisImageExifPlusData += "|pgr>SP "; }
                            else if (exposureProgramResult.match(/creative/) != null) { thisImageExifPlusData += "|pgr>Create "; }
                            else if (exposureProgramResult.match(/action/) != null) { thisImageExifPlusData += "|pgr>Ac "; }
                            else if (exposureProgramResult.match(/portrait/) != null) { thisImageExifPlusData += "|pgr>Portr "; }
                            else if (exposureProgramResult.match(/landscape/) != null) { thisImageExifPlusData += "|pgr>Lands "; }
                        }
                        // ISO
                        if (myExif_arr[e][0] == "ISO Speed Ratings") {
                            ISO = "[ISO " + myExif_arr[e][1].toString() + "]";
                        }
                        // Exposure Metering
                        if (myExif_arr[e][0] == "Metering Mode") {
                            var meteringResult = myExif_arr[e][1].toString().toLowerCase();
                            if (meteringResult.match(/unknown/) != null) { thisImageExifPlusData += "|meter>?? "; }
                            else if (meteringResult.match(/average/) != null) { thisImageExifPlusData += "|meter>Average "; }
                            else if (meteringResult.match(/center/) != null) { thisImageExifPlusData += "|meter>CenterWA "; }
                            else if (meteringResult.match(/spot/) != null) { thisImageExifPlusData += "|meter>Spot "; }
                            else if (meteringResult.match(/multispot/) != null) { thisImageExifPlusData += "|meter>MultiSpot "; }
                            else if (meteringResult.match(/pattern/) != null) { thisImageExifPlusData += "|meter>Patern "; }
                            else if (meteringResult.match(/partial/) != null) { thisImageExifPlusData += "|meter>Partial "; }
                            else if (meteringResult.match(/portrait/) != null) { thisImageExifPlusData += "|meter>Port "; }
                            else if (meteringResult.match(/other/) != null) { thisImageExifPlusData += "|meter>other "; }
                        }
                        // Exposure Bias Value == Exposure Compensation
                        if (myExif_arr[e][0] == "Exposure Bias Value") {
                            thisImageExifPlusData += "|compens>" + myExif_arr[e][1].toString() + " ";
                        }
                        //
                        // Exposure Mode
                        if (myExif_arr[e][0] == "Exposure Mode") {
                            thisImageExifPlusData += "|mode>" + myExif_arr[e][1].toString() + " ";
                        }
                        // Focal Length
                        if (myExif_arr[e][0] == "Focal Length") {
                            focalLength = "[FocLeng>" + myExif_arr[e][1].toString().replace(/\s/g,'') + "]";
                        }
                        // Pixel X,Y Dimension (both width & height at the same time)
                        if (myExif_arr[e][0] == "Pixel X Dimension") {
                            sizeCR2 = "[" + myExif_arr[e][1].toString() + "x" + myExif_arr[Number(e)+1][1].toString() + "]";
                        }
                        // White Balance
                        if (myExif_arr[e][0] == "White Balance") {
                            whiteBalance = "[WB>" + myExif_arr[e][1].toString() + "]";
                        }
                        // Flash
                        if (myExif_arr[e][0] == "Flash") {
                            // this is another way of getting the data from flash (there other properties if on)
                            if (activeDocument.xmpMetadata.rawData.match(/\<exif\:Fired\>(.+?)\<\/exif\:Fired\>/).length > 1) { //~ <exif:Fired>True</exif:Fired>
                                var flashTF = activeDocument.xmpMetadata.rawData.match(/\<exif\:Fired\>(.+?)\<\/exif\:Fired\>/)[1].toString().toLowerCase() == "true";
                                flash = (flashTF) ? "[FlashON]" : "[FlashOFF]";
                            }
                        }
                    }   
                }
                var result = activeDocument.name.replace(/\_/g,'') + " " + ISO + " " + focalLength + " " + whiteBalance + "\r"; // ;
                result += flash + " " + sizeCR2 + " "+ thisImageExifPlusData + "]"; //
                //
                var newLayer = makeTextLayer(result); 
                //
                function makeTextLayer(text) { 
                    var startRulerUnits = app.preferences.rulerUnits;
                    app.preferences.rulerUnits = Units.PIXELS;
                    app.preferences.typeUnits = TypeUnits.POINTS;
                    var FontName = "Trebuchet Ms";
                    var FontSize = 11;
                    var black = new SolidColor();
                    black.rgb.hexValue = '000000';
                    var newTextLayer = activeDocument.artLayers.add();
                    newTextLayer.kind = LayerKind.TEXT;
                    newTextLayer.textItem.kind = TextType.POINTTEXT;
                    newTextLayer.textItem.color = black;
                    newTextLayer.textItem.font = FontName;
                    newTextLayer.textItem.size = FontSize;
                    newTextLayer.textItem.contents = text.toString();
                    var toX = 50;
                    var toY = 80;
                    newTextLayer.textItem.position = [new UnitValue(toX, 'px'), new UnitValue(toY, 'px')];
                    app.preferences.rulerUnits = startRulerUnits;
                }