Skip Menu |

This queue is for tickets about the Imager CPAN distribution.

Report information
The Basics
Id: 106836
Status: resolved
Priority: 0/
Queue: Imager

People
Owner: Nobody in particular
Requestors: RKELSCH [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: 1.003
Fixed in: (no value)



Subject: read as raw data not working
I simply cannot get Imager to read a string as raw. It sets up an Imager object with the right dimensions, but the image inside it is blank. my $img = Imager->new( xsize => 100, # dimensions of the image block in string ysize => 100, channels => 4, # it's a 32 bit image type => 'raw', data => $image ); The object reports a 24 bit (not 32 which is also wrong) 100x100 image, but nothing is loaded (just black or a solid color). Have tried "store channels", "datachannels", "raw_storechannels", "raw_datachannels", or instead opening the string as a file and using "fh" instead of "data", but it still doesn't work. If I put a "file" parameter in there, and remove "type" and load a "PNG" or "JPEG" file, it works fine. I'm not sure if "data" is broken, or "type=raw" is broken.
On Wed Sep 02 20:40:05 2015, RKELSCH wrote: Show quoted text
> I simply cannot get Imager to read a string as raw. It sets up an > Imager object with the right dimensions, but the image inside it is > blank. > > my $img = Imager->new( > xsize => 100, # dimensions of the image block in string > ysize => 100, > channels => 4, # it's a 32 bit image > type => 'raw', > data => $image > ); > > The object reports a 24 bit (not 32 which is also wrong) 100x100 > image, but nothing is loaded (just black or a solid color). Have > tried "store channels", "datachannels", "raw_storechannels", > "raw_datachannels", or instead opening the string as a file and using > "fh" instead of "data", but it still doesn't work. If I put a "file" > parameter in there, and remove "type" and load a "PNG" or "JPEG" file, > it works fine. > > I'm not sure if "data" is broken, or "type=raw" is broken.
This looks like a bug in the way Imager::new() differentiates between creating a new blank image and reading an image from a file. Only the raw type requires the xsize and ysize parameters, but unfortunately Imager::new() uses the existence of those paramaters to decide whether to create a blank image or not. You can work around this by calling the read() method explicitly: my $img = Imager->new; $img->read( xsize => 100, # dimensions of the image block in string ysize => 100, raw_storechannels => 4, # it's a 32 bit image raw_datachannels => 4, # with 4 channels at the source raw_interleave => 0, # stored as rgbargba etc type => 'raw', data => $image ) or die "Oh no! ", $img->errstr; You may need to change raw_interleave, depending on how your image is laid out. I'll look at changing the way Imager::new() distinguishes between the two cases. The check for xsize/ysize is currently done first because having new() read files was bolted on fairly late in Imager's history, and I pereferred to break new code over breaking old code that was trying to make a new image. Tony
Subject: Re: [rt.cpan.org #106836] read as raw data not working
Date: Wed, 2 Sep 2015 21:18:21 -0600
To: bug-Imager [...] rt.cpan.org
From: Richard Kelsch <rich [...] rk-internet.com>
That did it! Thanks! Rich On 9/2/15 7:36 PM, TONYC via RT wrote: Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=106836 > > > On Wed Sep 02 20:40:05 2015, RKELSCH wrote:
>> I simply cannot get Imager to read a string as raw. It sets up an >> Imager object with the right dimensions, but the image inside it is >> blank. >> >> my $img = Imager->new( >> xsize => 100, # dimensions of the image block in string >> ysize => 100, >> channels => 4, # it's a 32 bit image >> type => 'raw', >> data => $image >> ); >> >> The object reports a 24 bit (not 32 which is also wrong) 100x100 >> image, but nothing is loaded (just black or a solid color). Have >> tried "store channels", "datachannels", "raw_storechannels", >> "raw_datachannels", or instead opening the string as a file and using >> "fh" instead of "data", but it still doesn't work. If I put a "file" >> parameter in there, and remove "type" and load a "PNG" or "JPEG" file, >> it works fine. >> >> I'm not sure if "data" is broken, or "type=raw" is broken.
> This looks like a bug in the way Imager::new() differentiates between creating a new blank image and reading an image from a file. > > Only the raw type requires the xsize and ysize parameters, but unfortunately Imager::new() uses the existence of those paramaters to decide whether to create a blank image or not. > > You can work around this by calling the read() method explicitly: > > my $img = Imager->new; > $img->read( > xsize => 100, # dimensions of the image block in string > ysize => 100, > raw_storechannels => 4, # it's a 32 bit image > raw_datachannels => 4, # with 4 channels at the source > raw_interleave => 0, # stored as rgbargba etc > type => 'raw', > data => $image > ) or die "Oh no! ", $img->errstr; > > You may need to change raw_interleave, depending on how your image is laid out. > > I'll look at changing the way Imager::new() distinguishes between the two cases. > > The check for xsize/ysize is currently done first because having new() read files was bolted on fairly late in Imager's history, and I pereferred to break new code over breaking old code that was trying to make a new image. > > Tony
Show quoted text
> On 9/2/15 7:36 PM, TONYC via RT wrote:
> > This looks like a bug in the way Imager::new() differentiates between > > creating a new blank image and reading an image from a file. > > > > Only the raw type requires the xsize and ysize parameters, but > > unfortunately Imager::new() uses the existence of those paramaters to > > decide whether to create a blank image or not.
This was fixed in Imager 1.004, thanks for reporting it. Tony