Fixing the gfxSpex image size function

Wednesday, 28 July 2010

We've recently been working on a new release of Cactushop. One of the modifications involves building a simple image library for the CMS system, and for this we used an existing function that has been part of Cactushop (and many other ASP applications) for years - gfxSpex.

Its a great function - you pass it the path to an image (gif, png, jpg) and it gives you back dimensions in pixels (as well as some other information). However, for some reason it was failing with jpgs - it worked fine for gifs and pngs, but not jpgs. Stranger still, it did work on some other test pages. And it certainly works on some sites. We eventually traced the problem to the config file of Cactushop. On every page we set the session.LCID (locale identifier) to 1033, for the USA.

Session.LCID = 1033

We do this so that all our code and queries can assume that dates will be in US format. We then use our own functions to customize the display of dates, currency and other locale-specific data. The problem only occured on pages where the session.LCID was set. So modifying the code a little greatly mitigated the problem...

If CInt(session.LCID) <> 1033 then
    Session.LCID = 1033
End if

This only set the LCID when it was incorrect - in most cases the LCID would not be changed and the problem with jpg sizes would not occur. But its also possible to set the LCID for the page... this is done at the very top of the ASP page...

<%@ LANGUAGE="VBSCRIPT" LCID=1033 %>

We can then remove the code setting it for the session, and gfxspex function then works perfectly. Its worth noting that this issue only occurs on some sites. The old code continues to work fine on some servers - so this might just be an issue with IIS7.

comments powered by Disqus
Powered by kartris