Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

raw image data?

by 23skiddoo (Sexton)
on Apr 21, 2009 at 15:17 UTC ( #759016=perlquestion: print w/replies, xml ) Need Help??

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

Greetings, monks. I am working with the Net::Twitter module to create a little script to send tweets of what I am listening to on Amarok. I also want to change my Twitter image with the currently playing album cover. The pod says that the method update_profile_image() expects "raw image data, not a pathname or URL to the image." Can someone point me to a module that will covert a local file to a thing that will work? I looked at Imager and Image::Magick but could not figure it out. Thanks! Eddie

UPDATE: I got on #net-twitter on and spoke with the author. It seems that my code is solid, but the reason it is failing is that twitter is simply too busy. Apparently, when their servers get overloaded, image uploads from the web interface or the API tend to fail.

Thanks to everyone that helped me out!


Replies are listed 'Best First'.
Re: raw image data?
by ikegami (Pope) on Apr 21, 2009 at 15:44 UTC
    That means it's expecting the contents of the file.
    my $raw_image_data = do { open(my $fh, '<:raw:perlio', $image_qfn) or die("Can't open image file \"$image_qfn\": $!\n); local $/; <$fh>; };
      Hmm... I tried a similar route before coming to the monastery:
      open my $fh, "<", $image_file or die "Can't open $image_file: $!"; my $raw = <$fh>;
      Which I believe is the same as the slurp() function mentioned above. It failed. I tried your code too, with the same failure. The file has to be under 700K and my test files have definitely been below that. There must be something else going on. Unfortunately the error messages returned don't provide much help.

      Thanks for your help!

        Did you binmode the filehandle?

        It's all fine and dandy until someone has to look at the code.
Re: raw image data?
by Anonymous Monk on Apr 21, 2009 at 15:23 UTC
    use File::Slurp; my $raw = slurp($filename);

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://759016]
Approved by ikegami
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2021-11-29 05:37 GMT
Find Nodes?
    Voting Booth?

    No recent polls found