diff options
Diffstat (limited to 'reolink/reolink')
| -rwxr-xr-x | reolink/reolink | 35 |
1 files changed, 29 insertions, 6 deletions
diff --git a/reolink/reolink b/reolink/reolink index e38eb55..a291aa8 100755 --- a/reolink/reolink +++ b/reolink/reolink @@ -117,6 +117,7 @@ use File::Basename; use File::Path 'make_path'; use File::Spec; use Getopt::Long; +use Image::Magick; use IO::Select; use OpenBSD::Pledge; use OpenBSD::Unveil; @@ -282,6 +283,8 @@ sub snapshot { my @t = localtime; my $fn = File::Spec->catfile (spool ($camera), sprintf ("%04d%02d%02d-%02d%02d%02d.jpg", $t[5]+1900, $t[4]+1, $t[3], $t[2], $t[1], $t[0])); + my $sn = $fn; + $sn =~ s|/([^/]+)$|/sm-$1|; # Could have changed since last time through make_path (spool ($camera), { mode => 0755 }) unless -d spool ($camera); @@ -291,6 +294,11 @@ sub snapshot { # take snapshot if ($r->Snap ($fn)) { warn "Error creating snapshot\n"; + } else { + my $image = Image::Magick->new (); + $image->Read ($fn); + $image->Resize ('1024x768'); # 4:3 - use 1280x960 if this is too small + $image->Write (filename => $sn); } $r->Logout; @@ -470,17 +478,26 @@ SLIDESHOW print $fh qq( "$camera" : [\n); - foreach my $image (<$spool/*.jpg>) { - if ($image =~ m/(\d{4})(\d{2})(\d{2})-(\d{2})(\d{2})(\d{2})\.jpg/) { + foreach my $image (<$spool/2*.jpg>) { + if ($image =~ m|/(\d{4})(\d{2})(\d{2})-(\d{2})(\d{2})(\d{2})\.jpg|) { my $file_time = mktime ($6, $5, $4, $3, $2 - 1, $1 - 1900); + my $title = "$1-$2-$3 $4:$5:$6"; + my $small = $image; + $small =~ s|/([^/]+)$|/sm-$1|; if ($file_time < $t) { debug ("delete $image ($file_time $t)"); unlink $image; + unlink $small if -f $small; } else { my $im = basename ($image); + if (-f $small) { + $small = basename ($small); + } else { + $small = ""; + } print $fh <<"IMAGE"; - { image: "$im", title: "$1-$2-$3 $4:$5:$6" }, + { image: "$im", small: "$small", title: "$title" }, IMAGE } } @@ -584,6 +601,7 @@ SLIDESHOW max-width: 100%; } img { + width: 100%; max-width: 100%; } video { @@ -615,9 +633,14 @@ SLIDESHOW current = slider.value; img = document.getElementById (id ("photo-display", camera)); - img.src = cameras[camera].spool + "/" + images[camera][current].image; + img_src = cameras[camera].spool + "/" + images[camera][current].image; + if (images[camera][current].small) { + img.src = cameras[camera].spool + "/" + images[camera][current].small; + } else { + img.src = img_src; + } a = document.getElementById (id ("photo-link", camera)); - a.href = img.src; + a.href = img_src; cap = document.getElementById (id ("photo-caption", camera)); cap.innerHTML = images[camera][current].title; } @@ -779,7 +802,7 @@ sub run { $i->add ($s); do { - snapshot; + snapshot (); maybe_generate_video (); respool_and_generate_slideshow (); |
