Re: Imager plays poorly with Storable?
From: Tony Cook (email@example.com)
Date: Fri 30 Jul 2010 - 04:44:52 GMT
On Thu, Jul 29, 2010 at 10:31:43PM -0400, Jason McIntosh wrote:
> 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?
Imager's image representation is handled mostly through XS, and is
stored as a C structure.
Unfortunately Imager doesn't have any support for Storable's hooks.
Also, if I did implement them, I'd also include the image data and
tags, and if you're only planning on retrieving the image width and
height, this would be huge overhead - you'd be better off caching just
the the width and height yourself.
If you just want the width and height, you might consider using
Image::Size, which I use in my own systems, even though I might be
loading the image into Imager later (typically in a separate process
though) for actual processing.