[英]Issues extracting exif data for exif 2.3 using PHP Version 5.2.9
[英]Extracting EXIF Data Using PHP
我正在為需要照片庫的客戶建立一個網站,我打算使用文件名作為alt標簽,但他希望我使用他放在EXIF數據中的關鍵字 - 因為我不是攝影師我真的不明白這方面的技術方面,但是,到目前為止我有一個腳本工作來獲取文件名,我希望它只需更改幾行代碼就可以得到EXIF而不是Filename。 這是我的代碼:
<?php
//The directory to your images folder, with trailing slash
$dir = "cms/gallery/photo/";
//Set the extensions you want to load, seperate by a comma.
$extensions = "jpeg,jpg";
//Set the number of images you want to display per page
$imagesPerPage = 3;
//Set the $page variable
if(!isset($_GET['page'])){
$page = 1;
}else{
$page = $_GET['page'];
}
//Load all images into an array
$images = glob($dir."*.{".$extensions."}", GLOB_BRACE);
//Count the number of images
$totalImages = count($images);
//Get the total pages
$totalPages = ceil($totalImages / $imagesPerPage);
//Make sure the page you are on is not greater then the total pages available.
if($page > $totalPages){
//Set the currnet page to the total pages.
$page = $totalPages;
}
//Now find where to start the loading from
$from = ($page * $imagesPerPage) - $imagesPerPage;
//Now start looping
for($i = $from; $i < ($from + $imagesPerPage); $i++){
//We need to make sure that its within the range of totalImages.
if($i < $totalImages){
$filename = explode('.', basename($images[$i])); // GET EXIF DESCRIPTION AS $FILENAME
//Now we can display the image!
echo "
<div class='galleryCellHolder'>
<div class='galleryCell'>
<a class='fancybox' rel='group' href='{$images[$i]}'><img class='galleryPhoto' src='{$images[$i]}' alt='" . $filename[0] . "'></a>
</div>
</div>
";
}
}
//Now to display the page numbers!
for($p = 1; $p <= $totalPages; $p++){
if($p == $page){
$tmp_pages[] = "<a class='noPagination'>{$p}</a>";
}else{
$tmp_pages[] = "<a class='pagination' href='?page={$p}'>{$p}</a>";
}
}
?>
<div class="clearLeft"></div>
<div id="pagination">
<?php
//Now display pages, seperated by a hyphon.
echo "<br />" . implode("", $tmp_pages);
?>
</div>
做這個:
$filedata = exif_read_data($images[$i]);
if(is_array($filedata) && isset($filedata['ImageDescription'])){
$filename = $filedata['ImageDescription'];
} else{
$filename = explode('.', basename($images[$i]));
$filename = $filename[0];
}
如果FileName
不在exif數據中, $filename
將包含路徑中的文件名。
正確的名稱可能與$filedata['ImageDescription']
。 它也可能在例如$filedata['FileName']
或$filedata['Title']
。 只是看看自己哪個有效
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.