Forum OpenACS Development: Proposal to make portrait-bits to serve images as real images

I mean, using real image-like url. Now, portrait-bits works with an url like /shared/portrait-bits.tcl?user_id=12345 what makes no sense to browsers to cache that as images.

That means to rewrite current portrait-bits url's as... something like /shared/portraits/12345/real-name.jpg, Or maybe /shared/portraits/12345.jpg, where 12345 is the user_id param, just to avoid collision between 2 different user portraits with the same image file name. And ".jpg" is the real file extension, so an api call should be use (of course) to get the user portrait url. (I've seen somewhere a manual url construction)

I don't know exactly how to do that. I've been looking packages/acs-subsite/www/image.vuh file, but I can't realize If I can use it for that purpose. I have tried, but due to user portraits have not set "read" privileges, a "not found" text page is served when the user is not a swa. Maybe, (another proposal) a default image should be served instead of a text/plain message.

<h2>Smaller versions</h2>
Maybe that should be another proposal but... there is also a feature I'd like to have on user-portraits: "smaller" versions. If the user upload a big file (let's say real-name.jpg), it'd be nice to have a real-name-small.jpg, real-name-thumbnail.jpg, real-name-square.jpg file names depending on different maximum values for each version. Maybe created at running time, when user uploads its portrait.

the square version is really nice to make a grid layout of images (for instance, agraduation class photo -in spanish: "<span lang="es">orla</span>") having control on how images are shown, and keeping the aspect ratio of them (cropping, instead of distorting them)

I've made something similar on another framework (PHP+Apache+GD library), so maybe I could do it on openACS using CR, but I'll need help for doing that.

Dear Miguel,

regarding the smaller versions you can generate them on the fly executing 'convert', an utility of ImageMagick.

I'll investigate that... but If a page has too many user portraits... It shouldn't be better having a file already created/converted for any image, instead of doing them on the fly?
See image-procs.tcl in acs-content-repository
and
acs-subsite/www/image.vuh

which are central tools.
Image procs can generate thumbnails.
image.vuh can generate the thumbnail (once) if it does not exist when referenced.

http://cvs.openacs.org/cvs/openacs-4/packages/acs-content-repository/tcl/image-procs.tcl?rev=1.6&view=markup

Basically if you reference an image as
/image/thumnail/${item_id}

it will find any CR item of image type or subtype and serve it up. If the named size (thumbnail in this case) does not exist it'll create it and save it in the CR.

You can set any sizes you want in image::get_convert_to_sizes. Probably can be made a parameter in the future.

It already creates thumbnail, view and avatar named sizes.
So you can use /image/avatar/${item_id}

You can also append a filename to the URL for a prettier url like
/image/avatar/${item_id}/portrait.jpg

It looks like image.vuh URL is
/image/${item_id}/thumbnail/${optional filename}

It also looks like the regexp for the url handler needs to be fixed to support all the sizes in convert_to_sizes proc.

So portraits need to have some sort of permissions set, or a way to bypass permissions?

Re: default image, that is also a good idea. I did that for one client.