Home > OS >  How to get the EXIF shutter count (imageNumber) using PHP?
How to get the EXIF shutter count (imageNumber) using PHP?

Time:12-25

I've been able to get EXIF data by using exif_read_data(). According to the EXIF documentation provided on PHP docs, there has to be an imageNumber tag (I understand it's not guaranteed), but I haven't been able to see anything like that on my test image (Unedited JPG from a Nikon D5100). The same image seems to carry information about the shutter count as per online shutter count websites.

Really appreciate it if you can shed some light on what I'm possibly doing wrong to get this number. Or is there any other place or method they store shutter count in image meta?

EDIT:

Here's the code I tried to work out, and I'm trying to get imageNumber which is apparently not available to get. But online tools show the shutter count on the same image. I'd like to get the same result using PHP (or even using another language). Any help is appreciated.

$exif_data = exif_read_data ( $_FILES['fileToUpload']['tmp_name']);
print_r( $exif_data);

CodePudding user response:

As per your example file it is specific to Nikon's MakerNote and in there specific to the D5100 model. Using ExifTool in verbose mode shows the structure:

> exiftool -v DSC_8725.JPG
...
JPEG APP1 (65532 bytes):
  ExifByteOrder = MM
    [IFD0 directory with 11 entries]
  | 0)  Make = NIKON CORPORATION
  | 1)  Model = NIKON D5100
...
  | 9)  ExifOffset (SubDirectory) -->
  |   [ExifIFD directory with 41 entries]
...
  | | 16) MakerNoteNikon (SubDirectory) -->
  | |   [MakerNotes directory with 55 entries]
...
  | | | 38) ShotInfoD5100 (SubDirectory) -->
  | | |   [BinaryData directory, 8902 bytes]
...
  | | | | ShutterCount = 41520

MakerNotes are proprietary: how data is stored there is up to each manufacturer. Documentations from those are rare - mostly hobbyists reverse engineer that information - that's why only selected software can read it at all for selected models. At this point you may realize that dozens of manufacturers with dozens of models exist, for which you all would have to interpret bytes differently - which is a lot of work! As per exif_read_data()s ChangeLog PHP 7.2.0 nowhere claims to support Nikon at all.

You have to either parse the MakerNote yourself or find PHP code/library/software which already did that for you. As a last resort you could execute non-PHP software (such as ExifTool) to get what you want.

  • Related