ExifTool Forum

ExifTool => Bug Reports / Feature Requests => Topic started by: mceachen on April 12, 2023, 01:41:39 AM

Title: How to determine the image content offset and length?
Post by: mceachen on April 12, 2023, 01:41:39 AM
I looked and couldn't find a tag that includes the byte count offset and length of bytestream of the primary image.

I'd like to be able to take a SHA256 of the image, after omitting all metadata. Is there an efficient way to do this?

Thanks for your time and efforts!
Title: Re: How to determine the image content offset and length?
Post by: Phil Harvey on April 12, 2023, 06:45:48 AM
You can get an MD5 like this:

exiftool -imagedatamd5 FILE

- Phil
Title: Re: How to determine the image content offset and length?
Post by: StarGeek on April 12, 2023, 11:48:39 AM
Quote from: mceachen on April 12, 2023, 01:41:39 AMI looked and couldn't find a tag that includes the byte count offset and length of bytestream of the primary image.

There isn't one that I recall and if there was, then Phil would have mentioned it.

QuoteI'd like to be able to take a SHA256 of the image, after omitting all metadata. Is there an efficient way to do this?

If you need SHA256 instead of MD5, take a look at this post (https://exiftool.org/forum/index.php?topic=9722.0), which was the old way of doing a MD5 hash.

Alternatively, you could parse the output of the -v3 (-verbose3) option (https://exiftool.org/exiftool_pod.html#v-NUM--verbose).  It won't give exact image starting point, but that could be computed.  JPEG SOS is Start of Scan (I think) and JPEG EOI is End of Image

Example:
C:\Programs\My_Stuff>exiftool -G1 -a -s -e -v3 y:\!temp\Test4.jpg
  ExifToolVersion = 12.60
  FileName = Test4.jpg
  Directory = y:/!temp
  FileSize = 445460
  FileModifyDate = 1680707743.45783
  FileAccessDate = 1681311542.93255
  FileCreateDate = 1680222709
  FilePermissions = 33206
  FileType = JPEG
  FileTypeExtension = JPG
  MIMEType = image/jpeg
JPEG DQT (65 bytes):
    0006: 00 02 01 01 01 01 01 01 01 01 02 02 02 02 02 02 [................]
    0016: 02 02 02 02 03 04 05 06 04 03 04 04 05 07 06 06 [................]
    0026: 06 05 06 06 06 06 07 09 07 06 08 09 0a 09 08 0b [................]
    0036: 08 06 06 0a 0a 0a 0a 0b 0c 0b 08 09 0c 0a 0a 0a [................]
    0046: 0a                                              [.]
JPEG DQT (65 bytes):
    004b: 01 02 02 02 02 02 02 05 03 03 05 0a 07 06 07 0a [................]
    005b: 0a 0a 0a 0a 0a 0a 0a 0a 0a 0a 0a 0a 0a 0a 0a 0a [................]
    006b: 0a 0a 0a 0a 0a 0a 0a 0a 0a 0a 0a 0a 0a 0a 0a 0a [................]
    007b: 0a 0a 0a 0a 0a 0a 0a 0a 0a 0a 0a 0a 0a 0a 0a 0a [................]
    008b: 0a                                              [.]
JPEG SOF0 (15 bytes):
    0090: 08 04 b5 06 d5 03 01 22 00 02 11 01 03 11 01    [.......".......]
  ImageWidth = 1749
  ImageHeight = 1205
  EncodingProcess = 0
  BitsPerSample = 8
  ColorComponents = 3
  YCbCrSubSampling = 2 2
JPEG DHT (28 bytes):
    00a3: 00 00 02 02 02 03 01 01 00 00 00 00 00 00 00 00 [................]
    00b3: 00 02 03 01 04 00 05 06 07 08 09 0a            [............]
JPEG DHT (90 bytes):
    00c3: 10 00 02 02 01 03 02 04 04 03 06 05 03 01 00 02 [................]
    00d3: 23 01 02 03 11 00 04 12 21 31 41 05 06 13 51 07 [#.......!1A...Q.]
    00e3: 22 61 71 08 32 81 09 14 91 a1 c1 f0 23 42 b1 d1 ["aq.2.......#B..]
    00f3: e1 15 52 f1 33 62 16 17 18 24 72 0a 82 25 43 92 [..R.3b...$r..%C.]
    0103: 19 34 a2 e2 26 53 a3 b2 c2 d2 1a 27 28 54 b3 c3 [.4..&S.....'(T..]
    0113: d3 35 36 44 45 63 73 74 83 93                  [.56DEcst..]
JPEG DHT (26 bytes):
    0121: 01 00 02 03 01 01 01 01 00 00 00 00 00 00 00 00 [................]
    0131: 00 01 02 00 03 04 05 06 07 08                  [..........]
JPEG DHT (65 bytes):
    013f: 11 00 02 02 01 03 02 04 02 09 02 05 03 04 02 00 [................]
    014f: 07 00 01 02 11 21 03 12 31 04 41 05 22 51 61 13 [.....!..1.A."Qa.]
    015f: 71 06 14 32 81 91 a1 b1 c1 f0 15 d1 07 23 42 52 [q..2.........#BR]
    016f: e1 24 33 f1 34 62 72 b2 25 92 16 53 43 d2 17 35 [.$3.4br.%..SC..5]
    017f: a2                                              [.]
JPEG SOS
JPEG EOI

Of course, this assumes a jpeg.
Title: Re: How to determine the image content offset and length?
Post by: mceachen on April 12, 2023, 01:19:06 PM
Thanks you two!

If I want to append ImageDataMD5 to the standard tags, is there a better way than using
-imagedatamd5 -all?

(Is "-all" equivalent to "-*"?)
Title: Re: How to determine the image content offset and length?
Post by: Phil Harvey on April 12, 2023, 04:16:11 PM
With both -imagedatamd5 and -all on the command line you will get two copies of ImageDataMD5.  Instead, do this:

exiftool -api requesttags=imagedatamd5 FILE

- Phil
Title: Re: How to determine the image content offset and length?
Post by: mceachen on September 04, 2023, 12:38:33 AM
Now that ExifTool uses

-ImageHashType
instead of -ImageDataMD5, is this the proper way to do it?

exiftool -api requesttags=imagedatahash -api imagehashtype=SHA256 FILE
This seems to work, but if there's a more correct way to do this (I'm using "-stay_open True" mode, fwiw), I'm all ears.

Thanks again for the assist!


Title: Re: How to determine the image content offset and length?
Post by: StarGeek on September 04, 2023, 04:20:18 PM
Yes, that would be the correct way to include the imagedatahash in the output without calling it specifically.
Title: Re: How to determine the image content offset and length?
Post by: mceachen on September 07, 2023, 01:09:46 PM
Thanks again!