From: Tony Cook Date: Sun, 8 Nov 2015 00:09:42 +0000 (+1100) Subject: Imager->new now attempts to read a file given any data source X-Git-Tag: v1.004~3 X-Git-Url: http://git.imager.perl.org/imager.git/commitdiff_plain/c1af64cab9d10c86d9c5a87818488164737a5c63 Imager->new now attempts to read a file given any data source Previously, attempting to read a raw image would simply return a blank image, since the xsize and ysize parameters are required when reading a raw image, and new() checked only those parameters to decide to return a blank image. --- diff --git a/Imager.pm b/Imager.pm index cc4ecb23..abac09c2 100644 --- a/Imager.pm +++ b/Imager.pm @@ -671,18 +671,13 @@ sub new { $self->{ERRSTR}=undef; # $self->{DEBUG}=$DEBUG; $self->{DEBUG} and print "Initialized Imager\n"; - if (defined $hsh{xsize} || defined $hsh{ysize}) { - unless ($self->img_set(%hsh)) { - $Imager::ERRSTR = $self->{ERRSTR}; - return; - } - } - elsif (defined $hsh{file} || - defined $hsh{fh} || - defined $hsh{fd} || - defined $hsh{callback} || - defined $hsh{readcb} || - defined $hsh{data}) { + if (defined $hsh{file} || + defined $hsh{fh} || + defined $hsh{fd} || + defined $hsh{callback} || + defined $hsh{readcb} || + defined $hsh{data} || + defined $hsh{io}) { # allow $img = Imager->new(file => $filename) my %extras; @@ -696,6 +691,12 @@ sub new { return; } } + elsif (defined $hsh{xsize} || defined $hsh{ysize}) { + unless ($self->img_set(%hsh)) { + $Imager::ERRSTR = $self->{ERRSTR}; + return; + } + } elsif (%hsh) { Imager->_set_error("new: supply xsize and ysize or a file access parameter or no parameters"); return; diff --git a/t/200-file/300-raw.t b/t/200-file/300-raw.t index ed92efe2..dddd690b 100644 --- a/t/200-file/300-raw.t +++ b/t/200-file/300-raw.t @@ -1,8 +1,8 @@ #!perl -w use strict; -use Test::More tests => 53; +use Test::More tests => 56; use Imager qw(:all); -use Imager::Test qw/is_color3 is_color4 test_image test_image_mono/; +use Imager::Test qw/is_color3 is_color4 test_image test_image_mono is_image/; -d "testout" or mkdir "testout"; @@ -294,6 +294,25 @@ SKIP: } } +{ # https://rt.cpan.org/Ticket/Display.html?id=106836 + my $im = test_image; + my $data; + ok($im->write(data => \$data, type => "raw", raw_interleave => 0), "save some raw image") + or diag $im->errstr; + my $im2 = Imager->new + ( + data => \$data, + filetype => "raw", + xsize => $im->getwidth, + ysize => $im->getheight, + raw_datachannels => $im->getchannels, + raw_storechannels => $im->getchannels, + raw_interleave => 0, + ); + ok($im2, "read raw image using new() method"); + is_image($im, $im2, "check they match"); +} + Imager->close_log; unless ($ENV{IMAGER_KEEP_FILES}) {