<?php
  // paintbrush_png_jpg.php
  // August, 2025
  // crontab php command line called way to backup Paintbrush created *.png to reduced size *.jpg
  $it = new GlobIterator(__DIR__ . "/*.png");
  $last2mis = 9020;
  foreach ( $it as $file ) {
    if ((time() - $file->getMTime()) <= $last2mis) {
      if (!file_exists(str_replace('.png','.jpg',$file)) && !file_exists(str_replace('.png','.jpeg',$file))) {
        exec("cd " . __DIR__ . '; /usr/local/bin/convert -quality 30 ' . $file . ' ' . str_replace('.png','.jpeg',$file));
      } else if (!file_exists(str_replace('.png','.jpg',$file)) && file_exists(str_replace('.png','.jpeg',$file))) {
        exec("cd " . __DIR__ . '; /usr/local/bin/convert -quality 30 ' . $file . ' ' . str_replace('.png','.jpg',$file));
      }
    }
  }
?>
