Programaticlly update images

I am upgrading a site to Kirby 3 and alot of the images do not have meta content files. Is there are a way to trigger a save on them all recursively, and set the template field in the images meta? Trying to avoid doing it by hand. Would this also fix any bad image file names?

You can loop through all images of the site or specific pages and then call $file->update():

<?php
foreach ( $site->index()->files() as $file ) {
  $file->update(
    [
      'template' => 'templatename',
    ]
  );
}

You can of course filter the files by all sort of criteria…

You might want to wrap this code in a try/catch clause to output possible errors (on screen, in a log file)