萬盛學電腦網

 萬盛學電腦網 >> 網絡編程 >> php編程 >> php通過exif

php通過exif

   這篇文章主要介紹了php通過exif_read_data函數獲取圖片的exif信息,默認情況下,PHP讀取圖片Exif信息模塊是不開啟的,我們需要先開啟這個模塊。開啟Exif模塊需要mbstring支持,這裡就不詳細說明了,我們來先看下函數的用法

  php獲取圖片的exif信息,php自帶一個exif_read_data函數可以用來讀取圖片的exif信息,代碼來自php手冊

  ?

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

  輸出結果如下

  ?

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

  以上所述就是本文的全部內容了,希望大家能夠喜歡。

copyright © 萬盛學電腦網 all rights reserved