Reputation: 25826
I have been reading some EXIF data with my PHP script. I want to determine for a certain image if the flash has been used. Here are the values returned by EXIF reader
0x0 = No Flash
0x1 = Fired
0x5 = Fired, Return not detected
0x7 = Fired, Return detected
0x8 = On, Did not fire
0x9 = On, Fired
0xd = On, Return not detected
0xf = On, Return detected
0x10 = Off, Did not fire
0x14 = Off, Did not fire, Return not detected
0x18 = Auto, Did not fire
0x19 = Auto, Fired
0x1d = Auto, Fired, Return not detected
0x1f = Auto, Fired, Return detected
0x20 = No flash function
0x30 = Off, No flash function
0x41 = Fired, Red-eye reduction
0x45 = Fired, Red-eye reduction, Return not detected
0x47 = Fired, Red-eye reduction, Return detected
0x49 = On, Red-eye reduction
0x4d = On, Red-eye reduction, Return not detected
0x4f = On, Red-eye reduction, Return detected
0x50 = Off, Red-eye reduction
0x58 = Auto, Did not fire, Red-eye reduction
0x59 = Auto, Fired, Red-eye reduction
0x5d = Auto, Fired, Red-eye reduction, Return not detected
0x5f = Auto, Fired, Red-eye reduction, Return detected
Which of them mean that the flash has been used?
Best regards, Mladjo
Upvotes: 5
Views: 4590
Reputation: 771
I believe if you convert the hex value to binary, the right-most digit then indicates if the flash actually fired or not.
Therefore:
Status | Hex | Binary | Fired |
---|---|---|---|
No Flash | 0x0 | 00000000 | No |
Fired | 0x1 | 00000001 | Yes |
"Fired, Return not detected" | 0x5 | 00000101 | Yes |
"Fired, Return detected" | 0x7 | 00000111 | Yes |
"On, Did not fire" | 0x8 | 00001000 | No |
"On, Fired" | 0x9 | 00001001 | Yes |
"On, Return not detected" | 0xd | 00001011 | Yes |
"On, Return detected" | 0xf | 00001111 | Yes |
"Off, Did not fire" | 0x10 | 00010000 | No |
"Off, Did not fire, Return not detected" | 0x14 | 00010100 | No |
"Auto, Did not fire" | 0x18 | 00011000 | No |
"Auto, Fired" | 0x19 | 00011001 | Yes |
"Auto, Fired, Return not detected" | 0x1d | 00011101 | Yes |
"Auto, Fired, Return detected" | 0x1f | 00011111 | Yes |
No flash function | 0x20 | 00100000 | No |
"Off, No flash function" | 0x30 | 00110000 | No |
"Fired, Red-eye reduction" | 0x41 | 01000001 | Yes |
"Fired, Red-eye reduction, Return not detected" | 0x45 | 01000101 | Yes |
"Fired, Red-eye reduction, Return detected" | 0x47 | 01000111 | Yes |
"On, Red-eye reduction" | 0x49 | 01001001 | Yes |
"On, Red-eye reduction, Return not detected" | 0x4d | 01001101 | Yes |
"On, Red-eye reduction, Return detected" | 0x4f | 01001111 | Yes |
"Off, Red-eye reduction" | 0x50 | 01010000 | No |
"Auto, Did not fire, Red-eye reduction" | 0x58 | 01011000 | No |
"Auto, Fired, Red-eye reduction" | 0x59 | 01011001 | Yes |
"Auto, Fired, Red-eye reduction, Return not detected" | 0x5d | 01011101 | Yes |
"Auto, Fired, Red-eye reduction, Return detected" | 0x5f | 01011111 | Yes |
Upvotes: 15
Reputation: 1
Why checking huge listings? With photo files, normally only occurrence is of interest, not the former (possibly inactive) switch position of the camera! The effective flash event can therefore be queried with just a few binary comparisons (see code snippet below). Have fun!
function effectiveFlash($flagval) {
/*
This function uses just 4 major bit comparisons
and responds with an easy-to-understand answer.
However, the code could be even shorter, e.g.
by returning simple symbols instead of text.
*/
$result = 'not fired'; // First we assume nothing!
// 1st check: Bit-1
if(($flagval & 1) > 0) {
$result = 'fired';
// Prepare opening and closing text part for possible subsequent information:
$sep = ' (Setting: ';
$end = "";
// 2nd check: Bit-16 plus possibly enclosed Bit-8
if (($flagval & 24) > 0) {
if (($flagval & 24) == 24) $result .= $sep . 'Auto';
else $result .= $sep . 'Compulsory';
$sep = ' + ';
$end = ')';
}
// 3rd check: Bit-64
if(($flagval & 64) > 0) {
$result .= $sep . 'Red Eye Reduction';
$sep = ' + ';
$end = ')';
}
// 4th check: Bit-4 plus possibly enclosed Bit-2
if(($flagval & 6) > 0) {
if(($flagval & 6) == 6) $result .= $sep . 'Return Light';
else $result .= $sep . 'No Return Light';
$sep = ' + ';
$end = ')';
}
// Now add the closing bracket ... that's it!
$result .= $end;
}
return 'Flash ' . $result;
}
// Examples:
echo effectiveFlash(1)."<br>\n";
echo effectiveFlash(16)."<br>\n";
echo effectiveFlash(31)."<br>\n";
echo effectiveFlash(77)."<br>\n";
The Output would be like this:
"Flash fired"
"Flash not fired"
"Flash fired (Setting: Auto + Return Light)"
"Flash fired (Setting: Compulsory + Red Eye Reduction + No Return Light)"
Upvotes: 0
Reputation: 3436
To simplify things, you can follow this: odd value means flash fired and even value (including zero) means flash did not fire.
You can get more information and meaning of each value at Tiff Tag Reference.
Upvotes: 1
Reputation: 10619
The flash property is actually a combination of the following flags:
0: FlashDidNotFire
1: FlashFired
2: StrobeReturnLightDetected
4: StrobeReturnLightNotDetected
8: CompulsoryFlashMode
16: AutoMode
32: NoFlashFunction
64: RedEyeReductionMode
To check if the flash has fired, bitwise AND the flash property with 1
:
$flashfired = ($exifflashproperty & 1) != 0;
Upvotes: 18