Search and show images with a given metadata

It would be possible, i.g. in localhost, to search and show images (in a given folder) with a given metadata. I.g. all images with “Giotto” as Artist exif metadata. BTW only exif metadata are available, or xmp as well?

The following isn’t the greatest, but it does the job for my personal website -

$file_ext = strtolower(pathinfo($_FILES['image']['name'], PATHINFO_EXTENSION));

/*
 * Set EXIF data info of image for database table that is
 * if it contains the info otherwise set to null.
 */
if ($file_ext === 'jpeg' || $file_ext === 'jpg') {
    /*
     * I don't like suppressing errors, but this
     * is the only way that I can so
     * until find out how to do it this will
     * have to do.
     */
    $exif_data = @exif_read_data($file_tmp);

    if (array_key_exists('Make', $exif_data) && array_key_exists('Model', $exif_data)) {
        $data['Model'] = $exif_data['Make'] . ' ' . $exif_data['Model'];
    }

    if (array_key_exists('ExposureTime', $exif_data)) {
        $data['ExposureTime'] = $exif_data['ExposureTime'] . "s";
    }

    if (array_key_exists('ApertureFNumber', $exif_data['COMPUTED'])) {
        $data['Aperture'] = $exif_data['COMPUTED']['ApertureFNumber'];
    }

    if (array_key_exists('ISOSpeedRatings', $exif_data)) {
        $data['ISO'] = "ISO " . $exif_data['ISOSpeedRatings'];
    }

    if (array_key_exists('FocalLengthIn35mmFilm', $exif_data)) {
        $data['FocalLength'] = $exif_data['FocalLengthIn35mmFilm'] . "mm";
    }

} else {
    $data['Model'] = null;
    $data['ExposureTime'] = null;
    $data['Aperture'] = null;
    $data['ISO'] = null;
    $data['FocalLength'] = null;
}

Though I have to look at the 3rd Party App myself.

Thank you. Sorry for my incompetence, but where should I set the files path?

Besides my aim is to search and show several images based on its metadata. And not to show metadata of already given images.

You can use scandir to search a folder (directory).
https://www.w3schools.com/php/func_directory_scandir.asp

uhm: but in this way I list all images, regerdless to its metadata. I want select only images with a given keyword (or metatag).

The scandir function creates an array of all filenames, not just image files (note first two items in the array will be ‘.’ and ‘..’). You need to loop through finding image files. I use explode with separator “.” to get the filename extensions. Then you can use exif_read_data:
https://www.php.net/manual/en/function.exif-read-data.php

Well, you only list them all if your code lists them all. Surely you would write some code to use scandir() to get the list of files, then extract the metadata for each one in turn, check to see if it matches your selection criteria, and then list those that do.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.