logo       
Google Custom Search
    AddThis Social Bookmark Button
-->

Re: [Perldl] Perl: loading pdls from images in memory scalar variables: msg#00000

Subject: Re: [Perldl] Perl: loading pdls from images in memory scalar variables
Joe,
        It's your lucky day. New feature added to the PDL-CVS for reading image
data from scalars. Just pass data=>$var to new(), which will work for
most types. WBMP and GD types can't be recognized from the binary data,
so you'll have to specify type=>'wbmp' or type=>'gd' for those.

-Judd


On Mon, 2007-01-08 at 14:19 -0500, zentara wrote:
> On Mon, 08 Jan 2007 12:45:24 -0600
> Judd Taylor <judd.t@xxxxxxxxxxxxxxxxxx> wrote:
> 
> >I'm not so certain it would be that simple... it all depends on the
> >format of the data you're giving me.
> >
> >It would make sense to have a new() that takes a piddle as input, but
> >supporting formats beyond that gets a little tricky. I know of many
> >formats for images in memory, and they're all different. For instance,
> >the PNG in-memory format is totally incomprehensible (which is why I use
> >GD).
> >
> >The PDL::IO::GD lib uses GD's internal gdImage C struct as it's internal
> >format. Only the pointer to that struct is passed to the Perl level.
> >
> >To be honest, it's been a really long time since I used GD::Image for
> >anything. Not being able to get to the data has been a show-stopper for
> >us PDL folks. 
> >
> >Give me some more info on your memory format, and I'll see whats up with
> >supporting it.
> >-Judd
> 
> Well it's not that important to have that feature, but almost every Perl 
> module
> dealing with graphics, now have the ability to read images in/out from/to 
> scalar
> strings.
> 
> ImageMagick has blobs:
> #!/usr/bin/perl                                                               
>             
> use warnings; 
> use strict; 
> use Image::Magick; 
> my $imgfile = shift; 
> my $image =Image::Magick->new();
> $image->Read($imgfile); 
> my $blob = $image->ImageToBlob(); 
> #and the opposite 
> my $output = Image::Magick->new(magick=>'jpg');
> $output->BlobToImage( $blob );
> $output->Resize(geometry=>'160x120'); $output->Write('z.jpg');                
> 
> ##########################################################
> 
> Imager and the Perl GD module have similar methods now for
> reading from perl scalars, they use the -data option or a reference
> to the scalar, like \$inline_image.
> 
> Here is a GD example, I get a binary image from the net
> which is in a scalar, and without saving it first as a temp
> file, I load it into GD, where I can manipulate it.
> 
> #!/usr/bin/perl -w
> use strict;
> use LWP::Simple;
> use GD;
> 
> my $URL = 'http://zentara.net/2uni2.jpg';
> my $content = get($URL) or die $!; 
> 
> #content now contains a binary string like
> # my $content = `cat image.jpg`
> 
> #in regular GD you can read this directly
> #from the scalar
> my $gdimage = new GD::Image($content); 
> 
> # I was hoping to convert to piddle right here
> # without a temp file
> 
> open(GD, ">$0.png") or die;                                                   
>         
>     binmode GD;                                                               
>             
>     print GD $gdimage->png;                                                   
>                  
>     close GD;            
> __END__
> 
> 
> So I was hoping that PDL::IO::GD could read in $content,
> as above, as opposed to writing it to a temp file first.
> 
> Anyways, the format of the scalar is still png, jpg, gif,
> or whatever, it's just in binary-string form, rather than a disk file.
> 
> Thanks for considering this,
> zentara
> 
-- 
____________________________
Judd Taylor
Software Engineer

Orbital Systems, Ltd.
8304 Esters Blvd, Suite 870
Irving, TX 75063-2209

judd.t@xxxxxxxxxxxxxxxxxx
(469) 442-1767 x127




<Prev in Thread] Current Thread [Next in Thread>