(none) imager-devel
/ help / lists / applications / search /

Imager plays poorly with Storable?

From: Jason McIntosh (
Date: Fri 30 Jul 2010 - 02:31:43 GMT

  • Next message: Tony Cook: "Re: Imager plays poorly with Storable?"


    I find that if I try to use Storable::freeze() on an Imager object
    after it's read an image from a file, the result is a suspiciously
    tiny piece of data (less than 100 bytes). If I try to thaw() that
    data, I get a segfault. This happens both on Perl 5.8 and Perl 5.12,
    and running the most recent versions of both Imager (0.75) and
    Storable (2.21).

    I suspect that my thought process might be entirely wrong here. My
    hope was that I could cache entire Imager objects, rather than just
    image data. (I discovered this problem not while using Storable, in
    fact, but CHI.)

    I frequently want to call Imager methods like getheight() and
    getwidth() on images after reading them from cache, and I thought I
    could save a step this way, versus having to let an Imager object
    process the image data every time it's loaded from cache.

    Am I overlooking (or under-thinking) something obvious?

    Sample segfaulty code:


    use warnings;
    use strict;

    use Imager;
    use Storable qw( freeze thaw );

    my $filename = "perfectly_good_file.png";

    my $imager = Imager->new;
    $imager->read( file => $filename );

    # This line prints the expected value...
    print "OK, I see a file with height " . $imager->getheight . ".\n";

    # This line prints a very small number...
    my $frozen = freeze( $imager );
    print "I froze the object. Serialized, it is of length " .
    length($frozen) . "\n";

    # Perl panics after this line.
    my $thawed = thaw( $frozen );
    print "Now I have thawed it again.\n";

    Jason McIntosh

    http://jmac.org ? 19508@xyz.molar.is ? @JmacDotOrg