Question

i have the following problem:

I work in maintenance in a new inherited project. In this project the developers work on metadata of image and video in this way:

function getRotationFromFile($realPath) {
    $retVal = Array();

    $cmd = variable_get("exiftool",null) . "\"$realPath\"" . " | grep -E 'Rotation|Camera Identifier'";
    exec($cmd, $output);

    foreach ($output as $row){
        $key = trim(strstr($row, ':', true));
        $value = trim(str_replace(": ", "", strstr($row, ': ')));
        $retVal[$key] = $value;
    }
    return $retVal;
}

As you can read, this function, call the exec(exiftool..) and retrieve some metadata. I know that in php exists exif_read_data, that done the same.

My questions are:

  1. What is the best solution?
  2. Who is the faster one?
  3. Who is the more "correct" one?
  4. Finally, i try to search but i don't find if exif_read_data use exiftool in source

Thank you in advance!

Was it helpful?

Solution 2

From what I can tell, exif_read_data will only read EXIF data, not any other sort of metadata, as well as being limited to Tiff and Jpg files. EXIF chunks only very rarely appear in video files. Additionally, the two tags you're looking for in that bit of code, Camera Identifier and Rotation, are not tags are part of the EXIF specification. Camera Identifier appears to be a Quicktime tag, while Rotation appears to be a Nikon and Canon makernotes tag.

One thing that could be done is to tell Exiftool to show only the tags you want rather than piping it through grep. This can be done by adding -CameraIdentifier -Rotation to the command line. The quiet option -q might also be useful for this.

You might also want to look into the Orientation tag, as that is the standard tag to hold the orientation for image files.

@tsmgeek probably has the best solution, as they are correct about the startup overhead.

OTHER TIPS

I created a PHP script that allows reading/writing via exiftool very fast. We use it with gearman so it runs as a background service, the slowest part of exiftool is starting it, then call it from your PHP script by passing a job to gearman. We run about 5 instances of this script and so it can service things quickly. A single process should be able to process about 100 files in around 1-2s, this ofcourse depends on file size and storage speed but it does scale nicely. This has been used in production for the last 5 months on our Digital Asset Management platform.

https://github.com/tsmgeek/ExifTool_PHP_Stayopen

PHP function exif_read_data supports only JPEG and TIFF file types. Command line utility exiftool - much more.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top