php通过exif_read_data函数获取图片的exif信息

这篇文章主要介绍了php通过exif_read_data函数获取图片的exif信息,默认情况下,PHP读取图片Exif信息模块是不开启的,我们需要先开启这个模块。开启Exif模块需要mbstring支持,这里就不详细说明了,我们来先看下函数的用法

php获取图片的exif信息,php自带一个exif_read_data函数可以用来读取图片的exif信息,代码来自php手册

  1. <?php
  2. echo "test1.jpg:<br />\n";
  3. $exif = exif_read_data('tests/test1.jpg', 'IFD0');
  4. echo $exif===false ? "No header data found.<br />\n" : "Image contains headers<br />\n";
  5. $exif = exif_read_data('tests/test2.jpg', 0, true);
  6. echo "test2.jpg:<br />\n";
  7. foreach ($exif as $key => $section) {
  8. foreach ($section as $name => $val) {
  9. echo "$key.$name: $val<br />\n";
  10. }
  11. }
  12. ?>

输出结果如下

  1. test1.jpg:
  2. No header data found.
  3. test2.jpg:
  4. FILE.FileName: test2.jpg
  5. FILE.FileDateTime: 1017666176
  6. FILE.FileSize: 1240
  7. FILE.FileType: 2
  8. FILE.SectionsFound: ANY_TAG, IFD0, THUMBNAIL, COMMENT
  9. COMPUTED.html: width="1" height="1"
  10. COMPUTED.Height: 1
  11. COMPUTED.Width: 1
  12. COMPUTED.IsColor: 1
  13. COMPUTED.ByteOrderMotorola: 1
  14. COMPUTED.UserComment: Exif test image.
  15. COMPUTED.UserCommentEncoding: ASCII
  16. COMPUTED.Copyright: Photo (c) M.Boerger, Edited by M.Boerger.
  17. COMPUTED.Copyright.Photographer: Photo (c) M.Boerger
  18. COMPUTED.Copyright.Editor: Edited by M.Boerger.
  19. IFD0.Copyright: Photo (c) M.Boerger
  20. IFD0.UserComment: ASCII
  21. THUMBNAIL.JPEGInterchangeFormat: 134
  22. THUMBNAIL.JPEGInterchangeFormatLength: 523
  23. COMMENT.0: Comment #1.
  24. COMMENT.1: Comment #2.
  25. COMMENT.2: Comment #3end
  26. THUMBNAIL.JPEGInterchangeFormat: 134
  27. THUMBNAIL.Thumbnail.Height: 1
  28. THUMBNAIL.Thumbnail.Height: 1