dougu5847 2013-06-04 00:49
浏览 131

使用php获取png格式图像的元数据[复制]

This question already has an answer here:

I can use exif tags for getting the metadata of a jpeg or a tiff format image.But what should I do to get png metadata?

Example: My code for getting exif tags:

 <?php
    $image = "NATU.png";
    $exif = exif_read_data($image, 0, true);
    foreach ($exif as $key => $section) {
    foreach ($section as $name => $val) {
    echo "$key.$name: $val <br>";
    } 
    } 
    ?>
</div>
  • 写回答

1条回答 默认 最新

  • dongyu2764 2013-06-04 00:52
    关注

    The PNG file format defines that a PNG document is split up into multiple chunks of data. You must therefore navigate your way to the chunk you desire.

    Assuming you have a well format PNG:

    <?php
      $fp = fopen('18201010338AM16390621000846.png', 'rb');
      $sig = fread($fp, 8);
      if ($sig != "\x89PNG\x0d\x0a\x1a\x0a")
      {
        print "Not a PNG image";
        fclose($fp);
        die();
      }
    
      while (!feof($fp))
      {
        $data = unpack('Nlength/a4type', fread($fp, 8));
        if ($data['type'] == 'IEND') break;
    
        if ($data['type'] == 'tEXt')
        {
           list($key, $val) = explode("\0", fread($fp, $data['length']));
           echo "<h1>$key</h1>";
           echo nl2br($val);
    
           fseek($fp, 4, SEEK_CUR);
        }
        else
        {
           fseek($fp, $data['length'] + 4, SEEK_CUR);
        }
      }
    
    
      fclose($fp);
    ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)