read bytes 0,1 # Byte ordering: 4949 = intel, 4D4D = motorola $imagecount = 0 $offset = read bytes 4-7 # first image directory while $offset != 0 $ifdlength = read first 2 bytes at $offset and multiply by 12 $imagecount++ $index = $offset + $ifdlength + 2 $offset = read 4 bytes at $index