使用按位枚举 EXIF flash 可读字符串

Using bitwise to enumerate EXIF flash readable string

当您使用 PHP 从图像中提取 EXIF 数据时,它有一个 Flash 值,它是一个整数。

例如,16 转换为十六进制时为 0x10。这意味着闪光灯已关闭,并且闪光灯没有闪光:

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

有没有办法在 PHP 中使用按位枚举它以便返回可读字符串。

例如,25 的值 0x19 可能看起来像这样(并且似乎有效):

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

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

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

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

这似乎可行,但我似乎无法使用原始示例等示例。

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

不要使用 dechex()。它returns一个字符串;您尝试使用的按位运算符对数字进行运算。 (25 是一个非常好的数字——即使您没有将它写成十六进制也没关系。)

您必须处理的一个复杂情况是 "auto" 是一个奇怪的标志组合:0x08 是 "off",0x10 是 "on",并且组合 both (0x10 + 0x08 = 0x18) 给你 "auto"。你需要小心处理这些。