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 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算