douhuang1973 2017-12-18 16:56
浏览 249
已采纳

使用exiftool将图片中的元数据提取到json对象中

I'm developing a website where I need to extract the metadata of an image (jpeg) with exiftool. I'm doing it with this code:

$cmd = exec("exiftool ".$this->url, $result);

$result is now a classic array:

array (size=113)
0 => string 'ExifTool Version Number         : 10.40' (length=39)
1 => string 'File Name                       : photo7.jpg' (length=44)
2 => string 'Directory                       : images' (length=40)
3 => string 'File Size                       : 139 kB' (length=40)
4 => string 'File Modification Date/Time     : 2017:11:26 16:27:05+01:00' (length=59)
5 => string 'File Access Date/Time           : 2017:12:17 23:07:18+01:00' (length=59)
6 => string 'File Inode Change Date/Time     : 2017:11:26 16:27:05+01:00' (length=59)
7 => string 'File Permissions                : rw-r--r--' (length=43)
8 => string 'File Type                       : JPEG' (length=38)
9 => string 'File Type Extension             : jpg' (length=37)
...

But I want to turn this array into an other array with meaningful keys and not numbers. Something even better would be to have a json object. In any case, I want the final array to looks like this:

    array (size=113)
'ExifTool Version Number' => string '10.40' (length=5)
'File Name' => string 'photo7.jpg' (length=10)
...

Is there a simple way to achieve this?

  • 写回答

2条回答 默认 最新

  • dousuize3082 2017-12-18 17:16
    关注

    Just split the strings at the colon...

    $result2 = array();
    foreach($result as $value){
        $tmp = preg_split("#\s*\:\s*#", $value);
        $result2[$tmp[0]] = $tmp[1];
    }
    $result = result2;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 Python安装cvxpy库出问题
  • ¥15 用前端向数据库插入数据,通过debug发现数据能走到后端,但是放行之后就会提示错误
  • ¥15 python天天向上类似问题,但没有清零
  • ¥30 3天&7天&&15天&销量如何统计同一行
  • ¥30 帮我写一段可以读取LD2450数据并计算距离的Arduino代码
  • ¥15 C#调用python代码(python带有库)
  • ¥15 矩阵加法的规则是两个矩阵中对应位置的数的绝对值进行加和
  • ¥15 活动选择题。最多可以参加几个项目?
  • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
  • ¥15 vs2019中数据导出问题