当你用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 中使用按位枚举它,以便可以返回可读的字符串。
例如,0x19
的值 25
可能如下所示(并且似乎有效(:
$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()
.它返回一个字符串;您尝试使用的按位运算符对数字进行操作。(25
是一个非常好的数字 - 你没有用十六进制写它的事实并不重要。
您必须处理的一个复杂问题是"auto"是标志的奇怪组合:0x08是"关闭",0x10是"打开",并且将两者组合在一起(0x10 + 0x08 = 0x18(会给你"自动"。您需要仔细处理这些。