Php 使用按位枚举EXIF闪存可读字符串
当您使用PHP从图像中提取EXIF数据时,它有一个整数Flash值 例如,16在转换为十六进制时为0x10。这意味着闪光灯已关闭,但没有启动:Php 使用按位枚举EXIF闪存可读字符串,php,bit-manipulation,exif,Php,Bit Manipulation,Exif,当您使用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 d
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。它返回一个字符串;您尝试使用的位运算符对数字进行运算。25是一个非常好的数字——事实上你没有用十六进制写它并不重要
您必须处理的一个复杂问题是,auto是一个奇怪的标志组合:0x08为off,0x10为on,并且将0x10+0x08=0x18组合在一起会提供auto。你需要小心处理这些