[Zope] Re: image hot fix

marc lindahl marc@bowery.com
Thu, 23 Aug 2001 22:24:13 -0400


Hi Philip,
I'm cc'ing the list, perhaps someone has some input...  comments
interleaved.

> From: Philip Aylesworth <phila@purpleduck.com>
> Date: Thu, 23 Aug 2001 20:36:13 -0400 (EDT)
> To: info@bowery.com
> Subject: image hot fix
> 
> 
> Hi Marc,
> 
> I have to tell you that this image hot fix is exactly what I need! I was using
> Photo but it is no longer supported and this does things more the way I want
> to.
> 
> I am modifying it so that it will have several default sizes that can be
> cached.

Actually, if you look at the code, i *think* I have stuff in there to allow
you to use it with a RAMCache.  The idea being, make a RAM cache for caching
all thumbnail images, not just private caching for each instance.  I'm still
unfamiliar with how that all works in Zope, but architecturally I think
that's the best place to put a cache (external to the images themselves).  I
still don't see how to get this caching to work for all instances, it seems
the caches need to add one instance at a time...

But this way, they are stored where appropriate (cached), but not stored
inside the image (which could lead to unneccessary data.fs bloat).

> I am not to swift with python yet so I just went in and duplicated the thumb
> method and made some methods called "preview", "small", and "medium"giving
> them
> default sizes of 160X120, 320X 240, and 640X480.

The way I have it working, if you call tag() with the same size twice, at
the least, the client browser should use the locally cached version (at
least, it did for me), so I don't see that it's necessary to have specially
named methods.  For example, in my CMFPhoto and in the original ZPhoto, the
thumbnail pages always call tag with a size of 80, so they'll be cached (at
least per client) the second time around.

>I have this working now but I
> noticed one little bug in your code. The "keys =" line reverses the height and
> width. I fixed this by replacing it with:
> 
> keys = {'width':int(width or height), 'height':int(height or width)}

Doh!  Thanks for pointing it out!  I guess that gives me a reason for
version 0.2 (along with changing the name to image HotPatch!) -- though I'm
hoping to figure out the RAMCache situation (help! somebody!) first...

> 
> Now I have one question, if you don't mind. How do I make the tag method
> return
> a URL for the size of image that I want? I see that you have thumb hard coded
> in
> there. If you have time to take a look at this I would really appreciate it.

I have thumb hard coded (in tag), because that's the method the browser will
then call (with arguments) to actually fetch the image.

I guess, if you're rolling with the three special method approach (though I
don't think it's necessary), then in tag I guess you'd either create a new
parameter for tag (size=[preview,small,medium]) or match one of the three
names with a range of sizes, and put more if/elses in there to return the
right one.

> 
> Thanks for the great work!
> 
> Phil.
> 
> Philip Aylesworth
> phila@purpleduck.com