I'm working on an image gallery with portraits where I extract text from Exif data. When I edit the images I am writing the names of the people which I later show in my image gallery as captions.
I would like to make a list, but can't figure out how to make it into an array from which I can exclude duplicates with array_unique()
.
My code is:
$imgdir = 'images/'; //pick your folder ie.: 'images/'
$current_folder = basename(dirname(__FILE__));
$allowed_types = array('png','jpg','jpeg','gif');
$dimg = opendir($imgdir);
while($imgfile = readdir($dimg)){
if(in_array(strtolower(substr($imgfile,-3)),$allowed_types)){
$a_img[] = $imgfile;
sort($a_img);
reset ($a_img);
}
}
$totimg = count($a_img);
?><!DOCTYPE html>
<html>
<head>
<title>Names listing</title>
</head>
<body>
<?php
for ($x=0; $x < $totimg; $x++){
if ($x == ($totimg-1))
$_content = (exif_read_data('images/'.$a_img[$x])[ImageDescription]).'';
else
$_content = (exif_read_data('images/'.$a_img[$x])[ImageDescription]).', ';
$_unique = $_content;
echo $_unique;
}
?>
</body>
</html>
If I have multiple images with the same person I get a list like:
John, John, Jane, Jane, Jane, ... etc.
What I would like is:
John, Jane, ... etc.
Thanks in advance.