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

Hey Monkies,

I'm trying to load the EXIF thumbnail from images, when they are present in the EXIF header, within Gtk2. The perldoc of Gtk2::Gdk::Pixbuf says I have to use pack(), so I can pass the data to Gtk2::Gdk::Pixbuf->new_from_data();


This is my code:
my $thumb = pack('a*',${ $image->get_exif->{ThumbnailImage} }); my $pixbuf = Gtk2::Gdk::Pixbuf->new_from_data($thumb,'rgb',TRU +E,8,160,120,640);

$image is an object which retrieves EXIF information, it works... I've already dumped the output to a file, it's an image. That's how I found out what the width and height were.
Now, my problem is that all thumbs are 'mangled'.. they're snowy black :-/

Any help, tips, pointers to URLs/docs is greatly appreciated!

Thanks,
a confused monkie..

to ask a question is a moment of shame
to remain ignorant is a lifelong shame

Replies are listed 'Best First'.
Re: How to use pack() with Gtk2::Gdk::Pixbuf
by zentara (Cardinal) on Sep 13, 2005 at 11:16 UTC
      yeah... was thinking about that already ;-)
      thanks for the advice tho...

      to ask a question is a moment of shame
      to remain ignorant is a lifelong shame

Re: How to use pack() with Gtk2::Gdk::Pixbuf
by insaniac (Friar) on Sep 13, 2005 at 13:21 UTC
    muppet on the gtk-perl mailinglist found the solution ;-)
    here's his message (well, at least the solution part ;) ):

    Is the image data actually raw, packed, 24-bit pixels? If it's in a compressed format, you'll have to do incremental loading with a PixbufLoader. /me pokes google for EXIF thumbnail format According to http://park2.wakwak.com/~tsuruzoh/Computer/Digicams/exif- + e.html#ExifThumbs the thumbnail will be JPEG or TIFF, not raw bits. Do this, instead: my $loader = Gtk2::Gdk::PixbufLoader->new; $loader->write ($data); $loader->close (); my $pixbuf = $loader->get_pixbuf (); (That code is from memory, check for yourself to make sure i'm not telling lies.)

    It works like a charm now ;-)

    to ask a question is a moment of shame
    to remain ignorant is a lifelong shame