gideondsouza has asked for the wisdom of the Perl Monks concerning the following question:

I'm a perl newbie and maybe I'm just doing this incorrectly.

I'm trying to download an image from some url into my server on amazon ec2. I then want to use Imager to load that file up. For the life of me I cannot understand why it is always undef!!. This is the code:

my $data = LWP::Simple::get($the_url); my $fh = File::Temp->new(); my $filename = $fh->filename; binmode ($fh); print $fh $data; #### img is ALWAYS undef! my $img = Imager->new(file => $filename, type => 'png'); close ($fh);

Am I doing this correctly? Any clues as to what I should be looking for?

Replies are listed 'Best First'.
Re: downloading an image from external server returns null always (error checking)
by Anonymous Monk on Mar 09, 2013 at 08:47 UTC

    Imager shows my $img = Imager->new(file=>$file) or die Imager->errstr();

    error checking is important

Re: downloading an image from external server returns null always
by choroba (Cardinal) on Mar 09, 2013 at 08:42 UTC
    I have no experience with Imager. But what about closing the file before creating the Imager object?
    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
Re: downloading an image from external server returns null always
by gideondsouza (Pilgrim) on Mar 09, 2013 at 09:16 UTC

    Thanks a ton guys.

    The or die part saved me life! :D, helped me figure what was going on. I'm still thinking in terms of C# sometimes

    Here is the end state : http://www.tryperl.com/dominantcolors/ . It's a demo for one of my perl modules