I’m trying to write EXIF data to a <span>
for all loaded in images.
That is working, but <span class="tag"></span>
is displaying the same exif data on all spans.
The console is outputting correct info about the Artist info. It’s only not correct distributed to the span.
The idea is that every image with it’s own Artist exif data is transferred to the <span class="tag"></span>
. So eventually every image gets a little text box on top of it, with this data.
I’m using the exif.js library.
My script how it looks now:
$(document).ready(function(){
window.onload = function() {
const row = document.getElementsByClassName('img1');
for (let i = 0; i < row.length; i++) {
console.log(row[i]);
EXIF.getData(row[i], function() {
myData = row[i];
console.log(myData.exifdata.Artist);
$('.tag').text(myData.exifdata.Artist);
});
} // end Array
}; // end window.onload
}); // end document.ready
My images are loaded in <div id="mygallery">
via PHP.
<div id="mygallery">
<?php
$folder_path = 'images/full/'; //image's folder path
$num_files = glob($folder_path . "*.{JPG,jpg,gif,png,bmp}", GLOB_BRACE);
$folder = opendir($folder_path);
if($num_files > 0)
{
while(false !== ($file = readdir($folder)))
{
$file_path = $folder_path.$file;
$file_path_thumb = $folder_path.$thumb;
$extension = strtolower(pathinfo($file ,PATHINFO_EXTENSION));
$files = substr($file, 0, strrpos($file, '.'));
if($extension=='jpg' || $extension =='png' || $extension == 'gif' || $extension == 'bmp')
{
?>
<a class="full" data-fancybox="gallery" href="<?php echo $file_path; ?>"><span class="tag"></span><img class="img1" src="images/thumb/<?php echo $files . "_thumb.". $extension; ?>">
</a>
<?php
}
}
}
else
{
echo "the folder was empty !";
}
closedir($folder);
?>
</div>
What I’m doing wrong?