Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

abstract out the picture taking

  • Loading branch information...
commit 37a853e156e782c7a92288b99cfbf92aa0b1d34f 1 parent 04c0d03
@lukec lukec authored
Showing with 16 additions and 5 deletions.
  1. +16 −5 lib/VHS.pm
View
21 lib/VHS.pm
@@ -48,11 +48,9 @@ sub take_picture {
my $now_hash = sha1_hex(scalar localtime);
my $short_hash = substr $now_hash, 0, 6;
my $pic_base = $self->config->{picture_base};
- my $filename = "$pic_base/$short_hash.jpeg";
- system("streamer -c /dev/video0 -b 16 -o $filename");
- my $tmp = $filename . ".tmp";
- system("jpegtran -rotate 180 $filename > $tmp");
- rename $tmp => $filename if -e $tmp;
+ my $filename = shift || "$pic_base/$short_hash.jpeg";
+
+ $self->picture_to_file($filename);
(my $short_name = $filename) =~ s#.+/(.+).jpeg#$1.jpg#;
my $short_file = "$pic_base/$short_name";
@@ -63,6 +61,19 @@ sub take_picture {
return $pic_uri;
}
+sub picture_to_file {
+ my $self = shift;
+ my $filename = shift;
+
+ my $jpeg = "$filename.jpeg";
+ system("streamer -c /dev/video0 -b 16 -o $jpeg");
+ unless (-e $jpeg) {
+ die "Couldn't take video to $jpeg";
+ }
+ system("jpegtran -rotate 180 $jpeg > $filename");
+ unlink $jpeg;
+}
+
sub run_command_from_arduino {
my $self = shift;
my $command = shift;
Please sign in to comment.
Something went wrong with that request. Please try again.