Skip to content

Commit

Permalink
abstract out the picture taking
Browse files Browse the repository at this point in the history
  • Loading branch information
lukec committed Apr 14, 2010
1 parent 04c0d03 commit 37a853e
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions lib/VHS.pm
Expand Up @@ -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";
Expand All @@ -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;
Expand Down

0 comments on commit 37a853e

Please sign in to comment.