Adam Howitt's Blog

Sep 14
2007

Glo-Brite Heavy Duty Section Launched

It's always a big relief to see a client really embrace a CMS and throw resources at it to get the website moving.  Glo-Brite is a client I've been working with for the last year and we launched their site about six months ago.  We stalled for a while but finally got back on track as Paul dedicated a resource to load all his heavy duty truck parts, uploading images, creating page titles and descriptions from their catalog.

The site is driven by my home grown CMS "Ham" (an anagram of my initials).  It is driven by an xml configuration file and includes rollback, file and image uploads and allows you to relate one object class to another.  It runs on MySQL and BlueDragon.  Image uploads are resized using the native java AWT image library.

<cffunction name="scaleImage" access="private" output="false" returntype="boolean" description="Scales an image by a factor or to fit within a max width/max height or both with configurable quality settings">
    <cfargument name="inFile" type="string" required="true">
    <cfargument name="outFile" type="string" required="true">
    <cfargument name="scale" type="numeric" required="false" default="0">
    <cfargument name="intMaxWidth" type="numeric" required="false" default="0">
    <cfargument name="intMaxHeight" type="numeric" required="false" default="0">
    <cfargument name="quality" type="numeric" default="0.30" required="false">
    <cfscript>
        fs = createObject("java","java.io.FileInputStream").init(arguments.inFile);
        jpegCodec=createObject("java","com.sun.image.codec.jpeg.JPEGCodec");
        decoder = jpegCodec.createJPEGDecoder(fs);
        srcImg = decoder.decodeAsBufferedImage();
        fs.close();
        if (arguments.scale neq 0 OR (arguments.intMaxWidth eq 0 AND arguments.intMaxHeight eq 0)) {
            variables.scale = arguments.scale;
        } else {
            w=srcImg.getWidth();
            h=srcImg.getHeight();
            if (arguments.intMaxWidth neq 0 AND arguments.intMaxHeight eq 0) {
                variables.scale = arguments.intMaxWidth / w;
            } else if (arguments.intMaxWidth eq 0 AND arguments.intMaxHeight neq 0) {
                variables.scale = arguments.intMaxHeight / h;
            } else if (h lt w) {
                variables.scale = arguments.intMaxWidth /w;
            } else {
                variables.scale = arguments.intMaxHeight / h;
            }
        }
        </cfscript>
        <cfscript>
        af = createObject("java","java.awt.geom.AffineTransform").getScaleInstance(variables.scale, variables.scale);
        hints = createObject("java","java.util.HashMap").init();
        rh = createObject("java","java.awt.RenderingHints").init(hints);
        transform = createObject("java","java.awt.image.AffineTransformOp").init(af,rh);
        destImg = transform.createCompatibleDestImage(srcImg, srcImg.getColorModel());
        transform.filter(srcImg, destImg);
        out = createObject("java","java.io.FileOutputStream").init(outFile);
        encoder = jpegCodec.createJPEGEncoder(out, jpegCodec.getDefaultJPEGEncodeParam(destImg));
        par = encoder.getDefaultJPEGEncodeParam(destImg);
        par.setQuality(JavaCast("float",arguments.quality), true); // set jpeg quality to 30 percent
        encoder.setJPEGEncodeParam(par);
        encoder.encode(destImg);
        out.close();
        return true;
    </cfscript>

</cffunction>

I'll post a follow up to this to explain how I arrived at this code as this was my first experiment at leveraging Java objects within my applications and once you get it, the process is actually really straightforward.

The site is configured with Google Analytics and we are tracking the goal that clients are submitting the contact form as the way to evaluate the performance of the content on the site and ad campaigns they are going to run.  Some areas are still a little rough but the client was willing to work on a "more content online is better than none while we wait for final sign off on every piece" basis.  There will be a few more design tweaks, plenty of content updates and the car and light duty AJAX driven part browser will be the last piece to launch.

Comments (Comment Moderation is enabled. Your comment will not appear until approved.)

There are no comments for this entry.

[Add Comment] [Subscribe to Comments]