Skip to content

Conversation

@thekid
Copy link
Owner

@thekid thekid commented Jan 1, 2025

This pull request extracts the lens model from EXIF / XMP as seen in xp-framework/imaging#6 and adds it to the meta information shown along with the image.

Examples

image

Updating the meta data

To fetch and update the meta data for all existing entries, use the following script:

$ for i in $(ls -1 Albums/*/*.md) ; do xp update-metadata.script.php $(dirname $i)  ; done
<?php

use com\mongodb\MongoConnection;
use de\thekid\dialog\Preferences;
use de\thekid\dialog\import\Source;
use de\thekid\dialog\processing\{Files, Images, Videos, ResizeTo};
use io\File;
use util\cmd\Console;
use web\Environment;

$preferences= new Preferences(new Environment('.'), 'config');
$conn= new MongoConnection($preferences->get('mongo', 'uri'));
$entries= $conn->collection($preferences->optional('mongo', 'db', 'dialog'), 'entries');

$files= (new Files())
  ->matching(['.jpg', '.jpeg', '.png', '.webp'], (new Images())
    ->targeting('preview', new ResizeTo(720, 'jpg'))
    ->targeting('thumb', new ResizeTo(1024, 'webp'))
    ->targeting('full', new ResizeTo(3840, 'webp'))
  )
  ->matching(['.mp4', '.mpeg', '.mov'], (new Videos())
    ->targeting('preview', new ResizeTo(720, 'jpg'))
    ->targeting('thumb', new ResizeTo(1024, 'webp'))
  )
;
$process= function($origin, $slug) use($entries, $files) {
  static $colors= ['-' => "\e[31m", '+' => "\e[32m"];

  $entry= $entries->find(['slug' => $slug])->first();
  $images= [];
  foreach ($entry['images'] ?? [] as $image) {
    $images[$image['name']]= $image;
  }

  $diff= 0;
  foreach ($files->in($origin) as $file => $processing) {
    $meta= $processing->meta($file);
    Console::writeLine(' => ', $slug, '/', $file->filename);

    // Compute and output difference
    $changes= [];
    foreach (array_diff_assoc($images[$file->filename]['meta'], $meta) as $key => $value) {
      $changes[$key]['-']= $value;
    }
    foreach (array_diff_assoc($meta, $images[$file->filename]['meta']) as $key => $value) {
      $changes[$key]['+']= $value;
    }
    foreach ($changes as $key => $operations) {
      foreach ($operations as $operation => $value) {
        Console::writeLine($colors[$operation], '   ', $operation, ' ', $key, ' => ', $value, "\e[0m");
      }
    }

    $images[$file->filename]['meta']= $meta;
    $diff+= sizeof($changes);
  }

  if ($diff) {
    Console::writeLine(' => ', $entries->update($entry->id(), ['$set' => ['images' => array_values($images)]]));
  } else {
    Console::writeLine(' => No changes to publish');
  }
};

$source= Source::in($argv[1]);
Console::writeLine("[+] \e[37;1m{$source->toString()}\e[0m");

// The entry itself
$process($source->origin(), $source->name());

// Check for children
foreach ($source->origin()->entries() as $path) {
  if ($path->isFolder() && (new File($path, 'content.md'))->exists()) {
    $process($path->asFolder(), $source->name().'/'.$path->name());
  }
}

@thekid thekid added the enhancement New feature or request label Jan 1, 2025
@thekid thekid merged commit ae00cee into main Jan 2, 2025
13 checks passed
@thekid thekid deleted the feature/metadata branch January 2, 2025 14:02
@thekid thekid mentioned this pull request Jan 4, 2025
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant