读取 EXIF 并确定闪光灯是否已闪光

发布于 2024-11-29 19:30:07 字数 1142 浏览 0 评论 0原文

我一直在用 PHP 脚本读取一些 EXIF 数据。我想确定某个图像是否使用了闪光灯。以下是 EXIF 读取器返回的值,

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

其中哪些值表示 Flash 已被使用?

此致, 姆拉乔

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

燃情 2024-12-06 19:30:07

flash 属性实际上是以下标志的组合:

0:  FlashDidNotFire
1:  FlashFired
2:  StrobeReturnLightDetected
4:  StrobeReturnLightNotDetected
8:  CompulsoryFlashMode
16: AutoMode
32: NoFlashFunction
64: RedEyeReductionMode

要检查 flash 是否已闪光,请将 flash 属性与 1 按位与:

$flashfired = ($exifflashproperty & 1) != 0;

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;
别靠近我心 2024-12-06 19:30:07

我相信,如果将十六进制值转换为二进制,最右边的数字将指示闪光灯是否实际闪光。

因此:

状态十六进制二进制已触发
无闪烁0x000000000
触发0x100000001
“已触发,未检测到返回”0x500000101
“已触发,检测到返回”0x700000111
“开启,未触发”0x800001000
“已启动,已触发”0x900001001
“开,未检测到返回”0xd00001011
“开,检测到返回”0xf00001111
“关,未触发”0x1000010000
“关,未触发,未检测到返回”0x1400010100
“自动,未检测到火”0x1800011000
“自动、触发”0x1900011001
“未检测到自动、触发、返回”0x1d00011101
“检测到自动、触发、返回”0x1f00011111
无闪光功能0x2000100000
“关闭、无闪光功能”0x3000110000
“已触发,红眼消除”0x4101000001
“已触发,红眼消除,未检测到返回”0x4501000101
“已触发,红眼消除,检测到返回”0x4701000111
“开启,红眼消除”0x4901001001
“开,红眼减少,未检测到返回”0x4d01001101
“开启,红眼消除,检测到返回”0x4f01001111
“关闭,红眼消除”0x5001010000
“自动,未触发,红眼消除”0x5801011000
“自动、触发、红眼消除”0x5901011001
“自动、触发、红眼消除、未检测到返回”0x5d01011101
“自动、触发、红眼消除、检测到返回”0x5f01011111

I believe if you convert the hex value to binary, the right-most digit then indicates if the flash actually fired or not.

Therefore:

StatusHexBinaryFired
No Flash0x000000000No
Fired0x100000001Yes
"Fired, Return not detected"0x500000101Yes
"Fired, Return detected"0x700000111Yes
"On, Did not fire"0x800001000No
"On, Fired"0x900001001Yes
"On, Return not detected"0xd00001011Yes
"On, Return detected"0xf00001111Yes
"Off, Did not fire"0x1000010000No
"Off, Did not fire, Return not detected"0x1400010100No
"Auto, Did not fire"0x1800011000No
"Auto, Fired"0x1900011001Yes
"Auto, Fired, Return not detected"0x1d00011101Yes
"Auto, Fired, Return detected"0x1f00011111Yes
No flash function0x2000100000No
"Off, No flash function"0x3000110000No
"Fired, Red-eye reduction"0x4101000001Yes
"Fired, Red-eye reduction, Return not detected"0x4501000101Yes
"Fired, Red-eye reduction, Return detected"0x4701000111Yes
"On, Red-eye reduction"0x4901001001Yes
"On, Red-eye reduction, Return not detected"0x4d01001101Yes
"On, Red-eye reduction, Return detected"0x4f01001111Yes
"Off, Red-eye reduction"0x5001010000No
"Auto, Did not fire, Red-eye reduction"0x5801011000No
"Auto, Fired, Red-eye reduction"0x5901011001Yes
"Auto, Fired, Red-eye reduction, Return not detected"0x5d01011101Yes
"Auto, Fired, Red-eye reduction, Return detected"0x5f01011111Yes
烟花肆意 2024-12-06 19:30:07

为了简化问题,您可以遵循以下原则:奇数值表示闪光灯已闪光,偶数值(包括零)表示闪光灯未闪光

您可以在 Tiff 标签参考中获取更多信息和每个值的含义

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.

楠木可依 2024-12-06 19:30:07

为什么要检查大量列表?对于照片文件,通常只对发生的事件感兴趣,而不是相机的前一个(可能不活动)开关位置!因此,只需进行一些二进制比较即可查询有效的闪光事件(请参见下面的代码片段)。玩得开心!

    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)"

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)"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文