Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Use the ps script to get the exif of the image without opening it in photoshop

Community Beginner ,
Jun 17, 2018 Jun 17, 2018

Use the ps script to get the exif of the image without opening it in photoshop?

QQ截图20180617191626.png

TOPICS
Actions and scripting
4.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Advocate ,
Jun 17, 2018 Jun 17, 2018

You might have a good look at Exiftool, which can read out pretty much any metadata of your document.

Hope this can help.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jun 17, 2018 Jun 17, 2018

Thank you,i know the software ,but i just went to use PS JavaScript 。。。。

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Jun 17, 2018 Jun 17, 2018

#target photoshop;

ExternalObject.AdobeXMPScript = new ExternalObject("lib:AdobeXMPScript");

var s = File.openDialog("Please select JPG file.","JPG File:*.jpg");

var file = new XMPFile(File(s).fsName, XMPConst.FILE_UNKNOWN, XMPConst.OPEN_FOR_READ);   

var xmp = file.getXMP();

if( xmp.doesPropertyExist(XMPConst.NS_EXIF, "PixelXDimension" ) ) {

    var x= xmp.getProperty(XMPConst.NS_EXIF, "PixelXDimension" );

    var y= xmp.getProperty(XMPConst.NS_EXIF, "PixelYDimension" );

    alert("X = " + x + " Y = " + y );

}else{

    alert("This files does not have EXIF dimensions");

    }

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 17, 2018 Jun 17, 2018

I used the same method but later I found it doesn't take into consideration if file was rotated in system (Windows / OS).

So later I created own method where I read binaries, while now I use even something simpler for all formats and rotations.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jun 19, 2018 Jun 19, 2018

00.jpg

this is ok!!!

but , Only for raw files? Why  so many images unable to read size information?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 19, 2018 Jun 19, 2018

Only for raw files? Why  so many images unable to read size information?

su仙人  – the script provided by SuperMerlin is looking specifically for EXIF resolution metadata.

If the file does not contain this metadata, then the size can’t be reported. This was the case for my Canon CR2 files. This was also the case for JPEG files where the metadata had been stripped out.

If a common resolution source could not be found for all file formats, then more complex script would be needed to look for different known metadata in different image file formats.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jun 20, 2018 Jun 20, 2018

Thanks so much for response

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Jun 20, 2018 Jun 20, 2018

Yes @Stephen_A_Marsh is correct if there is no EXIF if would not get the X/Y

This script should, but only for JPGs

#target photoshop;

String.prototype.WidthHeight = function(pos){

var wh = new Array();

var hi = this.charCodeAt(pos);

var lo = this.charCodeAt(pos+1);

wh.push( (hi << 8) + lo);

hi = this.charCodeAt(pos+2);

lo = this.charCodeAt(pos+3);

wh.push( (hi << 8) + lo);

return wh;

}

function main(){

var file =  File.openDialog("Please select JPG file.","JPG File:*.jpg");

file.open('r');

file.encoding='BINARY';

var filedata = file.read();

file.close();

var pos = new Array();

var RE = /\xFF\xC0/g;

while(match = RE.exec(filedata)){pos.push(match.index);}

var position = (pos[Number(pos.length-1)]);

var HeightWidth = filedata.WidthHeight(position+5);

var ratio = HeightWidth[1]/HeightWidth[0];

alert("X = " + HeightWidth[1] + " Y = " + HeightWidth[0]);

}

main();

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jun 20, 2018 Jun 20, 2018

Thanks for your reply

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 13, 2020 Jul 13, 2020

Hi @SuperMerlin. Part of your code is showing emojis for some reason... Can you clarify the string of characters needed to replace these?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 13, 2020 Jul 13, 2020

Just found the answer to my own question after trying a few strings... The emoji is being substituted for the sequential string of characters "8" and ")" when written on this forum...

 

Great script!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 13, 2020 Jul 13, 2020
LATEST

Is there also a way to capture the X and Y resolution metadata from PNG files without opening directly?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 19, 2018 Jun 19, 2018

You might have a good look at Exiftool, which can read out pretty much any metadata of your document.

Although  su仙人 requires Photoshop JavaScript code… Just in case anybody would like to explore the ExifTool suggestion, the command line code on a Mac OS would be:

exiftool -composite:imagesize 'path to file or folder'

or the shorthand form:

exiftool -imagesize 'path to file or folder'

or

exiftool -file:imagewidth -file:imageheight 'path to file or folder'

or the shorthand form:

exiftool -imagewidth -imageheight 'path to file or folder'

P.S. There are also EXIF tags that report dimensions (-ExifIFD:ExifImageWidth / -ExifIFD:ExifImageHeight or -ExifImageWidth / -ExifImageHeight), however they may not always exist if metadata has been removed, so the previous noted tags are safer to use.

NOTE: Simply swap the straight single quote marks for straight double quote marks on Windows OS.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 17, 2018 Jun 17, 2018

What file format - .jpg, .psd, other? What language do you use in your Photoshop - English, Japanese, other?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jun 17, 2018 Jun 17, 2018

is  jpg  , I use Chinese in my Photoshop

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 17, 2018 Jun 17, 2018

This scripts works for all kind of file formats also takes into consideration if the file was rotated in system:

(function(v){

     function sTT(v) {return stringIDToTypeID(v)}; function f(v1, v2) {

          if (arguments.length < 2) return r.getInteger(sTT(v1), 'px')

          return executeAction(sTT(v1 + 'ViewlessDocument'), v2)

     }

     (dsc1 = new ActionDescriptor()).putBoolean(sTT('preferXMPFromACR'), true)

     dsc1.putPath(sTT('file'), v), (r = f('open', dsc1)).getData(d = sTT('document'));

     (dsc2 = new ActionDescriptor()).putData(d, r.getData(d)), f('close', dsc2)

     return [f('width'), f('height')]

})(File('~/desktop/someFile.jpg'))

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Jun 17, 2018 Jun 17, 2018

You are still opening the document even though it can't be seen, the OP asked that it was not opened.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 17, 2018 Jun 17, 2018

Your method is good and as I said it's something I used too till I found I never can be sure was a file rotaed before I'd like later to open it in Ps. If I used it still then I could not immediately play some script on just opened image in Ps without checking its orientation and if wrong then doing necessary rotation.

Your method is the fastest though, but I don't think OP was clear enough what he wants. That script I wrote doesn't open a file that we can see it, so after all maybe for su仙人 that was what she wanted - no blinking effect.

And however it opens a file it works much faster than regular opening & closing a file, so when you remarkably see it.

Yours takes 1 mm, mine 33 mm, and normal one 150 mm for just small file. So 'viewless' one is 5 times faster than normal.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Jun 17, 2018 Jun 17, 2018

Yes you can process files with VB,C# etc without them showing and it does speed up the process and you have more control than usining viewless.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 17, 2018 Jun 17, 2018

As to C# I believe we can do much more than with Javascript, but for now I don't have power to learn another language. Regarding VB that's possible one day I will do that what I do now with ActionManager. I don't use VB language too until Javascript fails, so that's good notice.

To su仙人: if you want to be alerted in Photoshop of result, change:

return [f('width'), f('height')]

to:

return alert(return [f('width'), f('height')])

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 18, 2018 Jun 18, 2018

@Kukurykus:

     dsc1.putPath(sTT('file'), v)   always gives a PS error message. What's wrong with it? I am using PS CC 2018.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 18, 2018 Jun 18, 2018

Did you use your own path, or remained '~/desktop/someFile.jpg' ? If you did not use any other then you should save on desktop a file named someFile.jpg. If you did use other path, copy it here, maybe there's some mistake / it works in CC2018

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 18, 2018 Jun 18, 2018

If you want to get the EXIF info and not open the file, how about scripting it through Bridge? Or is that slower, as you can't use AM code?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Jun 19, 2018 Jun 19, 2018

They may not have Bridge installed? but for non raw files using xmpFile works just the same for Photoshop or Bridge.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines