Home > OS >  PHP array from .png and insert the title and subject into my database
PHP array from .png and insert the title and subject into my database

Time:10-02

i read a .png image XMP metadata with exiftool. it is working. I want to insert the title and subject into my database. How to work with this array? I need $title=title title.. and $description=description text.. and $subject=keyword1, keyword2..

Problem is, the array-numbers are different sometimes, i dont know why. Sometimes [39] is the title, sometimes [43] is the title.

Array
(
[0] => ---- ExifTool ----
[1] => ExifTool Version Number         : 11.88
[2] => ---- System ----
[39] => Title                           : title title title title text text text
[40] => Subject                         : keyword1, keyword2, keyword3, keyword4, keyword5
[41] => Description                     : description text description text

what i tried so far:

foreach($fullarraydata AS $arraynumber => $arraycontent) {
$result = ltrim(strstr($arraycontent, ':'), ':');
    if($arraynumber=='39')
    {$title=$result;}

not possible, because the array numbers are always different

CodePudding user response:

alternative solution, dont know a better one. Exiftool get title separate. Step2 Exiftool get Description, ..

CodePudding user response:

If you only want those two items, tell exiftool to extract only those two items.

exiftool -Title -Description file.png

This should guarantee the order. From the exiftool docs on the -sort option

Without the -sort option, tags appear in the order they were specified on the command line, or if not specified, the order they were extracted from the file.

For even more control over exiftool's output, look at the -p (-printFormat) option.

You should also be aware of exiftool Common Mistake #3. The startup time for exiftool is its biggest performance hit, so you don't want to call exiftool once for every file. You'll want to pass all the files you want to process and parse the output.

  • Related