Tag Archives: scale

Archiving thumnails of FTP camera images

This php script will iterate over an array $cams that has an element file that is the filename.

It uses the PHP Imagick package to resize the image and overlay a timestamp. The file timestamp is used so the time of the last ftp image is used, which may differ from the current time if the ftp has stalled. The image is then copied to an Hour/Minute specific folder for a 24 hour rolling archive.

$H = date('H');
$i = date('i');
$arcpath = $ftppath . $H . '/';
$arcpath = $ftppath . $H . '/' . $i . '/';

foreach ($cams as $cam)
  $pathfile = $ftppath . $cam['file'];
  if (file_exists($pathfile)) {
    $thumbname = $cam['file'] . '_320x240';

    $thumb = new Imagick($pathfile);

    $draw = new ImagickDraw();
    $draw->setFillColor(new ImagickPixel("#ffffff"));

    $draw->annotation(5, 12,  date ("F d Y H:i:s", filemtime($pathfile)));

    $thumb->writeImage($ftppath . $thumbname);
    copy($ftppath . $thumbname, $arcpath . $thumbname);