OK, most of the meat and potatoes of what I'm doing is in this
cfscript block.  I'm sure that it's possible to encapsulate this in a
much neater fashion, I just chose not to.

<cfscript>
        /* Set some variables that will make it easier to work with file and
server paths */
        filepath = cffile.serverdirectory & "\";
        imgname = cffile.serverfile;
        fullImgPath = filepath & imgname;
        thumbname = cffile.serverfilename & "_thumb." & cffile.serverfileext;
        fullThumbPath = filepath & thumbname;

        /* Invoke the image CFC */
        imgObj = CreateObject("component", "lib.cfc.tmt_img");
        
        imgObj.getDimensions("#fullImgPath#");
        
        /* Set image width and height as variables to make them easier to work 
with */
        imgwidth = imgObj.getwidth("#fullImgPath#");
        imgheight = imgObj.getheight("#fullImgPath#");
        
        if (imgwidth GT imgheight) {
                orientation = "landscape";
        } else if (imgwidth LT imgheight) {
                orientation = "portrait";
        } else {
                orientation = "square";
        }
        
        resizewidth = imgwidth;
        resizethumbwidth = maxthumbdimension;
        divide_by_value = (imgheight / imgwidth);
        
        if ((imgwidth GTE maxdimension) AND (imgheight GTE maxdimension) AND
(imgwidth GTE imgheight)) {
                resizewidth = maxdimension;
                resizethumbwidth = maxthumbdimension;
                diagnostics = diagnostics & "Landscape, both dimensions larger 
than max.<br>";
                resize = "true";
        } else if ((imgwidth GTE maxdimension) AND (imgheight GTE
maxdimension) AND (imgwidth LTE imgheight)) {
                resizewidth = (maxdimension / divide_by_value);
                resizewidth = round(resizewidth);
                resizethumbwidth = (maxthumbdimension / divide_by_value);
                resizethumbwidth = round(resizethumbwidth);
                diagnostics = diagnostics & "Portrait, both dimensions larger 
than max.<br>";
                resize = "true";
        } else if ((imgwidth GTE maxdimension) AND (imgheight LTE 
maxdimension)) {
                resizewidth = maxdimension;
                resizethumbwidth = maxthumbdimension;
                diagnostics = diagnostics & "Landscape, width greater than max,
height less than max.<br>";
                resize = "true";
        } else if ((imgwidth LTE maxdimension) AND (imgheight GTE 
maxdimension)) {
                resizewidth = (maxdimension / divide_by_value);
                resizewidth = round(resizewidth);
                resizethumbwidth = (maxthumbdimension / divide_by_value);
                resizethumbwidth = round(resizethumbwidth);
                diagnostics = diagnostics & "Portrait, width less than max, 
height
greater than max.<br>";
                resize = "true";
        } else {
                diagnostics = diagnostics & "Both dimensions smaller than max. 
[ELSE]<br>";
                resize = "false";
                /* Image is smaller than the maxdimension in both dimensions.
                        It won't resize the image, but what about sizing the 
thumbnail? */
                if ((imgwidth GTE maxthumbdimension) AND (imgheight LTE 
maxthumbdimension)) {
                        /*  */
                        resizewidth = imgwidth;
                        resizethumbwidth = maxthumbdimension;
                        diagnostics = diagnostics & "Landscape, larger than 
thumbmax but
smaller than max.<br>";
                        resize = "true";
                } else if ((imgwidth LTE maxthumbdimension) AND (imgheight GTE
maxthumbdimension)) {
                        resizewidth = imgwidth;
                        resizethumbwidth = (maxthumbdimension / 
divide_by_value);
                        diagnostics = diagnostics & "Portrait, larger than 
thumbmax but
smaller than max.<br>";
                        resize = "true";
                } else {
                        /* Image smaller than thumbnail in both dimensions.
                                Don't create new thumbnail. */
                        diagnostics = diagnostics & "Smaller than thumbmax. 
[ELSE]<br>";
                        resize = "false";
                }
        }
        
        /* Doublecheck the portrait/resizewidth = maxthumbdimension bug */
        if ((orientation EQ "portrait") AND (resizethumbwidth EQ 
maxthumbdimension)) {
                resizethumbwidth = (maxthumbdimension / divide_by_value);
                /* diagnostics = diagnostics & "Bug trapped!<br>"; */
        }

        if (resize EQ "true") {
                /* Scale down large images using the resizewidth value */
                imgObj.resize(fullImgPath, "#fullImgPath#", resizewidth);
                imgObj.resize(fullImgPath, "#fullThumbPath#", resizethumbwidth);
                diagnostics = diagnostics & "Resize true, Image and thumbnail 
created.<br>";
        } else if ((imgwidth LT maxthumbdimension) AND (imgheight LT
maxthumbdimension)) {
                imgObj.resize(fullImgPath, "#fullThumbPath#", imgwidth);
                diagnostics = diagnostics & "Resize false, Image and thumbnail 
created.<br>";
        } else {
                imgObj.resize(fullImgPath, "#fullThumbPath#", resizethumbwidth);
                diagnostics = diagnostics & "Resize false, but creating a 
properly
sized thumbnail. [ELSE]<br>";
        }
</cfscript>

If this isn't enough, I can make a zipped copy of the CFM template available.

Pete

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Find out how CFTicket can increase your company's customer support 
efficiency by 100%
http://www.houseoffusion.com/banners/view.cfm?bannerid=49

Message: http://www.houseoffusion.com/lists.cfm/link=i:4:220443
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54

Reply via email to