summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--reolink/Reolink.pm38
1 files changed, 30 insertions, 8 deletions
diff --git a/reolink/Reolink.pm b/reolink/Reolink.pm
index 5ce5bbd..ea95c4f 100644
--- a/reolink/Reolink.pm
+++ b/reolink/Reolink.pm
@@ -68,6 +68,12 @@ sub api {
return api ($this, %args);
}
+ if ($this->{debug}) {
+ if (! $resp->is_success) {
+ print Dumper $resp;
+ }
+ }
+
my $ret = $resp->is_success ? $resp->decoded_content : '[{"code":-1}]';
my $retref = decode_json ($ret);
@@ -103,6 +109,14 @@ sub new {
token => undef,
errors => 0
};
+
+ if ($args{image_quality_workaround}) {
+ $this->{image_quality_workaround} = 1;
+ }
+ if ($args{debug}) {
+ $this->{debug} = 1;
+ }
+
make_url ($this);
bless $this, $class;
@@ -519,6 +533,7 @@ seconds to run.
=cut
+use Image::Magick;
sub Snap {
my ($this, $filename) = @_;
# Generate random 16 char token.
@@ -534,16 +549,23 @@ sub Snap {
return 1;
}
- my $fh;
- unless (open ($fh, ">$filename")) {
- carp "Failed to open '$filename': $!";
- return 1;
- }
+ if ($this->{image_quality_workaround}) {
+ my $image = Image::Magick->new ();
+ $image->BlobToImage ($resp->decoded_content);
+ $image->Set (quality => 99);
+ $image->Write (filename => $filename);
+ } else {
+ my $fh;
+ unless (open ($fh, ">$filename")) {
+ carp "Failed to open '$filename': $!";
+ return 1;
+ }
- binmode $fh;
- print $fh $resp->decoded_content;
+ binmode $fh;
+ print $fh $resp->decoded_content;
- close $fh;
+ close $fh;
+ }
0;
}