Thursday, January 20, 2005

Images Are Fixed....Somewhat

Well, it took a bit of a hack to do it, but I managed to get the images working. And contrary to what I said, my hour or so of scripting was NOT a waste. In fact, it was a nice start. With a lot more hacking, I have a nice generic script working to serve links to any of my pbase images, and it does it automatically, so I don't have to add any files or settings for each new image.

What the script does is take an image ID and size from the URL query string. It then uses those parameters to construct a url to request from pbase. This url returns the pbase page in which the specified image of the specified size is displayed. The script then parses out the image url from the rest of the text and html. Now, at this point, my instinct was to tell the browser to redirect to the pbase image url. That seemed to work fine when viewing images, so I built in a bunch of intelligent url caching and such. Then when I put the links into a web page, I ended up with one problem. When redirecting off a single image or a local html page, the web browser doesn't specify a referrer. However, when viewing an image embedded into a web page from a web site, the referrer DOES get sent to pbase's server. Well, it turns out that some of their servers reject your request when there is a referrer from another site.

So my next attempt was to rewrite the script to have it download the images and cache the entire image locally. When the script does the request, it's sure not to pass along a referrer, so all works fine. With that problem solved, the last issue was what to do about the resized images that were missing. My solution there was to attempt to use the real image of that size from pbase, but when the image was missing, I found the largest available sized version of the image, downloaded, resized it locally, and saved it to a file. This seems to work fine, because I've yet to find any images where the original size was missing. However, I coded the script to handle that situation if it does occur. If the best image available is smaller than the size requested, I don't bother to upsample (what's the point). I just return the smaller image.

So, a little programming trickery and I've now hacked it to work. Now back to...what was this blog supposed to be about...oh yeah, photography!

No comments: