-
' . trim(file_get_contents($caption_file));
}
// Initialise variables
$image_title = '';
$image_description = '';
// 2. Check Exif metadata (Title and Description fields)
$exifData = @exif_read_data($image_path, 'IFD0');
if ($exifData !== false) {
if (isset($exifData['XPTitle']) && !empty(trim($exifData['XPTitle']))) {
$image_title = '' . trim($exifData['XPTitle']);
}
if (isset($exifData['ImageDescription']) && !empty(trim($exifData['ImageDescription']))) {
$image_description = '' . trim($exifData['ImageDescription']);
}
}
// 3. Check IPTC metadata (Title and Caption fields)
$size = getimagesize($image_path, $info);
if (isset($info['APP13'])) {
$iptc = iptcparse($info['APP13']);
if (!empty($iptc['2#005'][0])) { // 2#005 is the IPTC object name (title)
$image_title = '' . trim($iptc['2#005'][0]);
}
if (!empty($iptc['2#120'][0])) { // 2#120 is the IPTC caption (description) field
$image_description = '' . trim($iptc['2#120'][0]);
}
}
// 4. Check XMP metadata (Title and Description fields)
$xmpData = file_get_contents($image_path);
if (preg_match('/
-
Your directory of \'' . $dir . '\' could not be found.
'; } else { $dir_contents = scandir($dir); asort($dir_contents); foreach ($dir_contents as $file) { // Ignore images that have '_thumb' in the name if (strpos($file, '_thumb') === false) { $tmp = explode('.', $file); $file_type = end($tmp); if ($file !== '.' && $file !== '..' && in_array($file_type, $file_display)) { $filetitle = $file; $htmlId = generateHtmlIdFromFilename($file); $extension_pos = strpos($file, '.'); // Find position of the last dot $base_filename = substr($file, 0, $extension_pos); // Extract filename without extension $file_extension = substr($file, $extension_pos); // Extract file extension // Determine base directories $thumbnail_dir = ($use_separate_folders && !empty($thumbnail_dir)) ? $thumbnail_dir : $dir; $retina_dir = ($use_separate_folders && !empty($retina_dir)) ? $retina_dir : $dir; $caption_dir = ($use_separate_folders && !empty($caption_dir)) ? $caption_dir : $dir; $tags_dir = ($use_separate_folders && !empty($tags_dir)) ? $tags_dir : $dir; // Construct file paths $image_path = $dir . '/' . $file; if ($use_separate_folders) { // Use exact filename when separate folders are enabled $thumbnail_path = file_exists($thumbnail_dir . '/' . $file) ? $thumbnail_dir . '/' . $file : $image_path; $retina_image_path = file_exists($retina_dir . '/' . $file) ? $retina_dir . '/' . $file . ' 2x' : ''; $thumbnail_caption_file = $caption_dir . '/' . $base_filename . '.txt'; $lightbox_caption_file = $caption_dir . '/' . $base_filename . '.txt'; $tags_file = $tags_dir . '/' . $base_filename . '.txt'; } else { // Legacy behaviour (appending suffixes) $thumbnail = $base_filename . '_thumb' . $file_extension; $retina_image = $base_filename . '@2x' . $file_extension; $retina_image_alt = $base_filename . '_@2x' . $file_extension; // Alternative format $thumbnail_path = file_exists($thumbnail_dir . '/' . $thumbnail) ? $thumbnail_dir . '/' . $thumbnail : $image_path; // Check for both retina image formats if (file_exists($retina_dir . '/' . $retina_image)) { $retina_image_path = $retina_dir . '/' . $retina_image . ' 2x'; } elseif (file_exists($retina_dir . '/' . $retina_image_alt)) { $retina_image_path = $retina_dir . '/' . $retina_image_alt . ' 2x'; } else { $retina_image_path = ''; // No retina image found } $thumbnail_caption_file = $caption_dir . '/' . $base_filename . '_thumb.txt'; $lightbox_caption_file = $caption_dir . '/' . $base_filename . '_text.txt'; $tags_file = $tags_dir . '/' . $base_filename . '_tags.txt'; } // Get captions (ignoring missing files) $lightbox_content = getImageCaption($caption_dir, $file, 'both', '', 'strong', 'span'); $thumbnail_content = getImageCaption($caption_dir, $file, 'title', '
', 'strong', 'span'); // Get image dimensions $dimensions = getimagesize($image_path); $thumb_dimensions = getimagesize($thumbnail_path); // Get image date/time $datetime = getImageDateTime($image_path); // Get tags $tags = getImageTags($tags_dir, $file); ?>