0

When you pull EXIF data from an image with PHP, it has a Flash value which is an integer.

For example, 16 which when converted to hex is 0x10. This means the flash was switched off, and the flash didn't fire:

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

Is there a way to enumerate this in PHP using bitwise so that a readable string can be returned.

For example, a value of 25 which is 0x19 would look perhaps something like this (and seems to work):

$fired = 0x01;
$auto = 0x18;

$flashValue = dechex(25); // 0x19

$parts = [];
if ($flashValue & $fired)
{
    $parts[] = 'Fired';
}
if ($flashValue & $auto)
{
    $parts[] = 'Auto';
}

$string = implode(', ', $parts); // "Fired, Auto"

This seems to work but examples such as the original example I can't seem to get working.

SpongeBobPHPants
  • 641
  • 7
  • 19

1 Answers1

1
$flashValue = dechex(25); // 0x19

Don't use dechex(). It returns a string; the bitwise operators you're trying to use operate on numbers. (25 is a perfectly good number -- the fact that you didn't write it in hexadecimal doesn't matter.)

One complication you will have to deal with is that "auto" is a weird combination of flags: 0x08 is "off", and 0x10 is "on", and combining both (0x10 + 0x08 = 0x18) gives you "auto". You will need to handle these carefully.