Gregory's Blog

Extending Application.cfc's using mappings and proxies

One of the most frustrating things that I have had to deal with in ColdFusion is trying to create an external application that is open to the general public and having to secure a portion of that site with an application within a subfolder and extending the logic from base application.cfc. I'll walk you through the current approach that developers use to solve this as well as showing you how to additionally use mapping when there may be a hosting provider that uses virtual directories.

This is a rather long article, if you want to jump to the condensed summary, scroll down to the bottom of this page.

Many years ago, the first time that I tried to perform this, I received the following message no matter what I tried: "Could not find the ColdFusion component or interface xxx'. In a nutshell, the problem using this approach is that both the root and the subfolders have the same name, i.e. Application.cfc, and ColdFusion can't properly identify what component to extend. Finally, after some serious investigation, someone came up with the idea to create a proxy.cfc that resides in the same root directory as the root Application.cfc, and the Application.cfc in the subfolder extends an empty proxy.cfc that extends the root cfc like so:

root directory: Application.cfc
This root Application.cfc does not extend anything

Also in the root directory: Proxy.cfc
Proxy.cfc has the following code, it's essentially empty. The only thing that the Proxy.cfc does is to extend the Application.cfc that is in the same directory:
view plain about
1<cfcomponent extends="Application">

Subdirectory such as a folder named admin.
This subdirectory has another Application.cfc. Let's say that this component is responsible for securing the application and has login logic as well as debugging settings for example. This Application.cfc will extend the Proxy.cfc to gain the methods and properties of the Application.cfc in the root directory like so:
view plain about
1<cfcomponent displayname="Admin" extends="Proxy.cfc">
2<!--- Lots of code --->

This approach was a godsend and it was heavily blogged about. Ben Nadel has made a number of very helpful posts which I will share at the bottom of this article.

This works quite well unless you're on a hosted domain or a server that uses virtual directories. In this case, we are in the same original boat in which we started from. Now we are back into the "Could not find the ColdFusion component or interface xxx' hell!

There is a solution for this tricky problem though, we need to also use mapping!

It is a common misnomer that you can't use mapping to extend components. I am not quite sure where this misconception originally came about, but it has been proven that this is just not true. There are occasions where we must use mapping to solve some annoying problems, like here.

This particular site is hosted by They are a fine company to deal with, but the server that my site is hosted on has some idiosyncrasies due to the directory structure. Here, when I use the Proxy.cfc method to extend the logic from the base Application.cfc to the Application.cfc in the admin folder I receive the dreaded 'could not find the ... component' error. When I first saw it I was dismayed thinking not this again, so I turned to ColdFusion CFC mapping. Mapping tells ColdFusion where to find the file and what the file relationships are.

Let's review CFC structure that was just discussed. For example, imagine the following directory structure:

root directory: i.e.

As discussed, we have an Application.cfc and the Proxy.cfc in the root directory, and we have the Application.cfc in the 'admin' subdirectory. The Proxy.cfc extends the Application.cfc, also in the root directory, and the Application.cfc in the subdirectory (admin) extends the Proxy.cfc in the root directory.

root directory: contains both Application.cfc and Proxy.cfc (that extends the root Application.cfc).
subdirectory: Application.cfc (that extends Proxy.cfc).

Now we need to also add the following mapping in the root Application.cfc. This mapping logic should be near the top of the root Application.cfc, and it should not be within any of the Application.cfc event handlers (onApplicationStart, onApplicationRequest, etc). This mapping code does not need to be anywhere else other than the root Application.cfc:

view plain about
1<!--- Define application-specific mappings. These will be used to point to this application.cfc when we extend it in the admin/Administrator.cfc template using the Proxy.cfc that resides in the same folder as this Application.cfc. --->
2<cfset this.mappings = structNew() />
3<!--- Mapping for the ROOT Application.cfc --->
4<cfset this.mappings["rootCfc"] = getDirectoryFromPath(getCurrentTemplatePath()) />
5<!--- Mapping for the admin SUBDIRECTORY Application.cfc. Note the admin prefix is attached at the end of this line. This points to the admin folder. --->
6<cfset this.mappings["adminCfc"] = getDirectoryFromPath( getCurrentTemplatePath() & "/admin" ) />

I used rootCfc to identify the Application.cfc in the root directory, whereas adminCfc applies to the Application in the admin directory. These variables can be named anything. Note that the "/admin" string at the end of the adminCfc mapping points to the 'admin' folder, which is a subdirectory.

Now that we have the mappings in the root Application.cfc, we need to apply them to the extends statement in Application.cfc located in the subdirectory. In the /admin/Application.cfc template use:


view plain about
1<cfcomponent displayname="xxx" sessionmanagement="xx" clientmanagement="xx" extends="rootCfc.Proxy">
2<!--- Logic --->

Of course, rootCfc tells the Application.cfc in the subdirectory to look for the Proxy.cfc template in the root directory. Like other 'extend' statements, you don't need to specify '.cfc' at the end of Proxy.

You don't need to use this 'extend' mapping in either the root Proxy.cfc or Application.cfc templates. They can already find each other as they are both in the same root directory.


view plain about
1<cfcomponent extends="Application">


For the sake of absolute clarity:
root Application.cfc
Contains the mapping logic. Has the mappings for both of the root and subdirectory.
This mapping logic should be near the top of the root Application.cfc, and it should not be within any of the Application.cfc event handlers (onApplicationStart, onApplicationRequest, etc).
Does not use an 'extend' statement

view plain about
1<cfset this.mappings = structNew() />
2<cfset this.mappings["rootCfc"] = getDirectoryFromPath(getCurrentTemplatePath()) />
3<cfset this.mappings["adminCfc"] = getDirectoryFromPath( getCurrentTemplatePath() & "/admin" ) />

root Proxy.cfm
A simple 'extends="Application" works.
No mapping logic.

view plain about
1<cfcomponent extends="Application">

subdirectory Application.cfc
The extends statement must be the mapping variable name of the folder (rootCfc), a dot (.), and finally the name of the Proxy.cfc template without the .cfc prefix (Proxy)
No mapping logic.

view plain about
1<cfcomponent displayname="Admin" sessionmanagement="yes" clientmanagement="yes" extends="rootCfc.Proxy">

My apologies for being so verbose. I annoyed myself while writing this- but not as annoyed when I was while trying to solve this problem!

Take care!

Related External Posts:

This entry was posted on January 29, 2021 at 10:31 PM and has received 307 views.

How to make the perfect social media sharing image - part 6 Validation tools and tips

In this last post in this series, I will provide to links to some social image sharing validator tools and provide a few tips and tricks that I learned along the way.

After creating the proper social media images and fine tuning the social media meta tags that are required, you can validate how each site will display your page using the tools below.

Facebook Sharing Debugger

The Facebook Sharing Debugger will validate your og meta tags and scrape the social media image. It's relatively straightforward to use. Just enter in the URL of the page that you want to validate, and the debugger will scrape your page and show you if any errors were made. When you first enter the URL, it will take several seconds to generate the page, and if this page was not shared before, it will prompt you to fetch new information. Click on the button to fetch new information, and the debugger will list out data along with error information.

The debugger will not immediately generate the Facebook sharing preview as it is crawling your page in the background, wait several minutes and refresh the page, and the image preview should be displayed. If you have errors indicating that you have missing tags, you can ignore these, as long as you have all of the essential tags.

If you don't like the look of the images, you can make some changes, but come back here and regenerate the preview on the pages that you have shared the URL to.

If you're using Galaxie Blog, I have a utility tool in /common/utilities/cfimage.cfm that will allow you to reprocess the images quickly. For non Galaxie Blog users, I have provided instructions below, and I placed the utility script on Git hub.

Twitter Card Validator

The Twitter Card Validator is a bit easier to use, and it responds faster than the Facebook Sharing Debugger. Like Facebook, all that you need is to input your URL. After entering the URL, Twitters tool should immediately display your page preview. However, it is not easy to change the appearance of the preview after it has been made. I'll show you some tricks to re-create the preview.

How to Regenerate a Twitter Preview

Twitter will cache your preview once the page has been shared, or a Twitter Card Preview has been made. However, it can be quite problematic to refresh the cache once made. I learned a few tricks and will show you a bullet proof way to change your preview if you have to make any changes.

Go to the Twitter Open Graph meta tags in your page. Append something unique on the twitter:image tag like so. If you're using ColdFusion you can simply create a UUID. Other languages have the same capabilities. All you need to do is make sure that the URL is unique.

view plain about
1meta name="twitter:image" content=""

Once you have made the URL to the image unique, Twitter thinks that you have changed the image entirely, and will clear the cache and refresh the preview.

Note: you'll have to get a Facebook and Twitter Developer Account to use these tools.

Creating Social Media Images

I have put a cfimage.cfm template on GitHub for you to generate Social Media Images. I use this to generate social media images for my older posts. The usage is pretty simple. Upload the cfimage file to your server. then drop the original image in a enclosures folder, and create two new folders within the enclosures folder named twitter and facebook. In the socialMediaImagePath variable, put in the full image path for the type of image that you want to create. Go to the URL of your cfimage.cfm template with a browser, and the images will be saved underneath the '/enclosures/facebook' or '/enclosures/twitter' folders.

view plain about
1<!-- This is the only line that you should adjust --->
2<cfset socialMediaImagePath = "D:\home\\wwwroot\enclosures\DSC_0518.JPG">
3<!--- Consume the createSocialMediaImages(socialMediaImagePath, socialMediaImageType) function --->    
4<cfset createSocialMediaImages(socialMediaImagePath, 'facebook', '')>
5<cfset createSocialMediaImages(socialMediaImagePath, 'twitter', '')>

Other Social Media Validators

There are other tools for validation for different media platforms, such as Twitters Post Inspector, and Pinterest Rich Pin's Validator that I will cover at a different time.

Happy Coding!

This entry was posted on November 4, 2019 at 3:40 PM and has received 854 views.

How to make the perfect social media sharing image - part 5 Essential Meta Tags

How to make the perfect social media sharing image - part 5 Essential Meta Tags

Sharing your content on social media can have dramatic results at driving more traffic to your site. In my own experience, sharing my own content can drive 50% more traffic to the site. Along with adding the properly sized images, we need to make use of the correct meta tags. I have made several passes at improving the logic that Galaxie Blog uses to auto-generate the tags, and will share my experience with you. If you are using Galaxie Blog, the auto-generation of these tags is done for you.

Each social media site has it's own rules for generating the meta tags. Facebook prefers open graph tags, Twitter can use the open graph tags, but it has a slew of it's own proprietary tags, and Google +, LinkedIn, and Pinterest prefer schema markup tags, which I will not cover here.

Open Graph Tags

The following open graph tags are essential for Facebook

<meta property="og:image" content="URL to the social sharing image.">
<meta property="og:site_name" content="The site name (ie Galaxy Blog). " />
<meta property="og:url" content="The URL to the article" />
<meta property="og:title" content=" Must be 25 characters or less, especially for mobile" />
<meta property="og:description" content="Should be up to two sentences long, but under 30 characters for decent mobile rendering" />

The og:image:height and og:image:width tags are helpful, but not necessary. Facebook will correctly determine the proper image size as long as you stay within the Facebook recommendations.

Essential Twitter Tags

<meta name="twitter:card" content="summary_large_image">Use 'summary_large_image' if you're following along with this article
<meta name="twitter:site" content="@Site or article URL">
<meta name="twitter:title" content="The title of your site or article">
<meta name="twitter:description" content="Description, should be less than 200 characters">
<meta name="twitter:image" content="URL to the social sharing image.">

In the next article, I will go over some useful validation tools and share some tips and tricks with that I found.

This entry was posted on November 2, 2019 at 11:07 PM and has received 677 views.

How to make the perfect social media sharing image - part 4 Image Examples

After the last entry, I wanted to show you the social media images that were created by ColdFusion. Each of these images match the exact recommended size and the ratio aspect that are recommended by the various social media platforms. I'll show you the actual images that were created, and how the social media platform displayed the images after I shared the previous article.

The images

The first image to the left is the original image that was uploaded. This is a picture of my dog, Toby, a super-smart, 13 y.o. bundle of energy running in the snow. The second image, in the middle, is the Facebook social media image, and the image to the right is the Twitter social media image. All of the social media images are copies of the original.

Galaxie Blog will automatically take the image that you want to post, and create Facebook and Twitter social media images that are sized per the social media's recommendations. The Facebook social media image is 1200 pixels wide, and 630 in height. Twitter is similar, but just a hair shorter. They are 1200 pixels wide, and 628 pixels in height.

How the page renders on social media sites

Below are the social media sites render the page when it is shared. The images below are actual screen shot's of the last post I shared in part 3 of this series. Again, the image to the left is the original. The middle image is how Facebook presents the site, and the image to the right is how Twitter displays the share.

Both Facebook and Twitter will take the images that were created by Galaxie Blog, and resize them into their own format. As long as the images either meet the maximum or minimum dimensions as they do here, the site presentation of the share will look good.

Note: this approach works for Slack and LinkedIn sites, but this is outside of the narrow Facebook and Twitter scope that I wanted to blog about.

Next up in this series, how to properly use the meta tags for social media sharing.

This entry was posted on November 1, 2019 at 11:45 PM and has received 869 views.

How to make the perfect social media sharing image - part 3 Get the code...

In this post, I will share how I implemented logic to have Galaxie Blog automatically create social media sharing images for you when uploading an image for a given post.


When a Galaxie Blog owner creates a post using the administrative interface, there is an option to upload an enclosure by clicking a Choose File button at the end of the add entry page. The interface is simple, when the Choose File button is clicked, it opens up a file browser and the user selects the image that they want to be displayed at the top of the post.

In this post, the picture above is an abstract image that is 2200 pixels wide, and 1760 pixels in height. However, the social media images that the code below produces from this image will have different sizes that are optimized for both Facebook and Twitter. Galaxie Blog has always created a responsive image that automatically adjusts itself to fit on any modern device, however, I have now implemented logic that will manipulate the selected image and create both Facebook and Twitter social media images as well. Here is my approach...


To use this to create and save social media images, all that you need to do is invoke the createSocialMediaImages function below. It takes three arguments, the URL of the image that you want to perform operations on, the social media platform, and optionally, the Social Media Image Type. If the social media type argument is left blank (which is what I use in Galaxie Blog), the function will automatically determine the size and the proper aspect ratio. Here is the production code for Galaxie Blog that is working right now:

view plain about
1<!--- Set the path. --->
2    <cfset socialMediaImagePath = "D:\home\\wwwroot\blog\enclosures\aspectRatio1.jpg">
3    <!--- Automatically generate social media images for Facebook, Twitter, Instagram and LinkedIn. --->
4    <cfset createSocialMediaImages(socialMediaImagePath, 'facebook', '')>
5    <cfset createSocialMediaImages(socialMediaImagePath, 'twitter', '')>
6    <cfset createSocialMediaImages(socialMediaImagePath, 'instagram', '')>
7    <cfset createSocialMediaImages(socialMediaImagePath, 'linkedIn', '')>

Logic Walkthrough

I am assuming that if you're reading this, you're someone with the technical skills that can read this and try it out, so I'll jump right in to briefly cover the core logic of this approach. For the sake of clarity, I will only cover how the logic creates Facebook social media images. Most of the logic for the other platforms are the same, and I'll provide the full code at the end of the article.

Once the blog image is selected by the blog owner, Galaxie Blog will first get the width and height of the uploaded enclosure image that was just uploaded.

view plain about
2    action = "info"
3    source = "#socialMediaImagePath#"
4    structname="imageInfo">

The logic will then compare the height and width of the original image and determine which type of image will be used. Essentially, are we going to use the largest image type specified by the social media platform, or the minimum depending upon the image that was just uploaded.

view plain about
1<cfcase value="facebook">
2    <!--- Is the original image larger or smaller than Facebook's large image size? If larger, use the larger image dimensions specified by the social media platform. If the original image is smaller, use a smaller sized image. We are going to use similiar logic for every social media platform. --->
3    <cfif imageInfo.width gte facebookSharedImageWidth and imageInfo.height gte facebookSharedImageHeight>
4        <!--- Use the larger social media format. --->
5        <cfset socialMediaImageType = "facebookSharedImage">
6    <cfelse>
7        <cfif imageInfo.width gte facebookLinkRectangleImageWidth and imageInfo.height gte facebookLinkRectangleImageHeight>
8            <cfset socialMediaImageType = "facebookLinkRectangleImage">
9        <cfelse><!---<cfif imageInfo.width gte facebookLinkRectangleImageWidth and imageInfo.height gte facebookLinkRectangleImageHeight>--->
10            <!--- Use the facebookLinkSquareImage --->
11            <cfset socialMediaImageType = "facebookLinkSquareImage">
12        </cfif><!---<cfif imageInfo.width gte facebookLinkRectangleImageWidth and imageInfo.height gte facebookLinkRectangleImageHeight>--->
13    </cfif>

First, we will double check the images again to make sure that the uploaded image has a larger size than the social media sharing image that we will create. If the uploaded image is larger, we'll set the width and height to match the larger image type. If the uploaded image is smaller than the largest recommended size, we will use the minimum size recommended by the social media platform, and we may set a pre-crop variable to true if necessary. We'll cover this logic next.

view plain about
1<cfcase value="facebookSharedImage">
2    <!--- Is the original image larger or smaller than the large image size? If larger, use the larger image dimensions specified by the social media platform. If the original image is smaller, use the miniumum size. We are going to use the same logic for every social media type. --->
3    <cfif imageInfo.width gte facebookSharedImageWidth and imageInfo.height gte facebookSharedImageHeight>
4        <!--- Use the larger social media format. --->
5        <cfset thisImageWidth = facebookSharedImageWidth>
6        <cfset thisImageHeight = facebookSharedImageHeight>
7    <cfelse>
8        <!--- Use the rectangular facebook format. --->
9        <cfset thisImageWidth = facebookLinkRectangleImageWidth>
10        <cfset thisImageHeight = facebookLinkRectangleImageHeight>
11        <cfset preCrop = true>
12    </cfif>

Resizing a copy of the original uploaded image

Next we'll check to see if the original image is twice as wide as the targetted social media size. If it is, or if the preCrop variable was set in the previous switch statements, we will create a copy of the original image, and then resize the new image. The code below illustrates this. I removed all of the code other than the Facebook code.

view plain about
1<cfif preCrop>
3    <!--- Create a new image --->
4    <cfset shareImage = imageNew(socialMediaImagePath)>
6    <!--- Handle small images. --->
7    <!--- This logic is only invoked for Facebook rectangle links. --->
8    <cfif socialMediaImageType eq 'facebookLinkRectangleImage'>
10        <!--- Resize the new image. For portrait images, we are going to resize the image to 550 pixels wide. --->
11        <cfset imageResize(shareImage, 550, '')>
12        <!--- We know the width of the new image that was just created (550), now get it's height --->
13        <cfset shareImageWidth = imageGetHeight(shareImage)>
14        <!--- Crop the resized image from the center (centerCrop(path/image, originalWidth, originalHeight, newWidth, newHeight). We don't need to determine an aspect ratio. It is a square. --->
15        <cfset shareImage = centerCrop(shareImage, 550, shareImageWidth, thisImageWidth, thisImageHeight)>
17    </cfif><!---<cfif (socialMediaImageType eq 'facebookLinkRectangleImage'>--->

Maintaining the aspect ratio using our nifty ColdFusion ratio calculator function

One of the most critical requirements or this is having the ability to resize images while maintaining the targeted aspect ratio. I could not find a ColdFusion function that did this, so I had to built my own. If you play around with manipulating images and aspect ratios, this type of function should belong in your own toolbox.

Our ratioCalculator function below takes 3 arguments. The aspectRatioWidth and aspectRatioHeight arguments should match the recommended width and height of our targetted social media image that are indicated in the prior post. For the large Facebook Shared Image, the ratio aspect is 1200 pixels wide, and 630 pixels in height. We'll go ahead and plug these values in for the first two arguments as this is the aspect ratio that we want to keep, no matter what size we eventually resize the image to. The third argument is the newWidth argument. Here, the newWidth argument will either be: the original width of the uploaded image: or, the new width when we resized the image in the step above when the size of the uploaded image was twice the width of the recommended Facebook image size.

The ratio calculator function will take these three values, and return the height that is needed to maintain the original aspect ratio. To get the new height of the image, all that we need to specify is the recommended width and height, provided by the social media platform, and the new width that we want to resize an image to be. The new width argument can be smaller, or larger, than the aspect ratio size. No matter what you plug in for the new width, the aspect ratio will be maintained.

view plain about
1<cffunction name="ratioCalculator" access="public" output="true" returnType="numeric" hint="This is used to determine the new dimensions needed to fit a certain width while maintaining the specified aspect ratio. I am using this to determine how to resize an image to meet the aspect ratio used by varius social media sites.">
2    <cfargument name="aspectRatioWidth" required="yes" hint="Specify the original width of the image.">
3    <cfargument name="aspectRatioHeight" required="yes" hint="Specify the original height of the image.">
4    <cfargument name="newWidth" required="yes" hint="Specify the desired width of the new image.">
6    <cfset newHeight = (arguments.aspectRatioHeight / arguments.aspectRatioWidth) * arguments.newWidth>
8    <cfreturn newHeight>

Cropping the images

The code has two cropping functions, centerCrop, and horizontalCrop. The centerCrop function is used when we have a landscape image, and the horizontalCrop function is used when using a portrait image.

The centerCrop function takes five arguments, we need to specify the full path of the image, or the variable of the image if we are creating a new image using the newImage ColdFusion function. The original width and original height arguments using the social media recommended size. Here, we are using the large Facebook size of 1200 for the originalWidth, and 630 for the originalHeight. The fourth argument, width, is either the width of the uploaded image, or the width of the newly resized image, and finally, new height, which is provided by the ratioCalculator function that we just covered above. This function will crop the image from the center.

view plain about
1<cffunction name="centerCrop" access="public" output="true" returnType="string" hint="Used to crop an image with a desired size that is smaller both horizontally and vertically than the original image. This will crop the image from the center.">
2        <cfargument name="imagePath" required="yes" hint="Provide either the full original path of the image, or the actual ColdFusion image using the newImage function.">
3        <cfargument name="originalWidth" required="yes" hint="Provide the original width of the image.">
4        <cfargument name="originalHeight" required="yes" hint="Provide the original width of the image.">
5        <cfargument name="newWidth" required="yes" hint="Provide the desired width of the cropped image.">
6        <cfargument name="newHeight" required="yes" hint="Provide the desired height of the new cropped image.">
7        <!--- Local debugging carriage. If something goes awry, set this to true. --->
8        <cfset debug = true>
10        <!--- This algorithm was found at --->
11        <cfset originalImage = "#arguments.imagePath#">
12        <!--- Make a copy of the original image. --->
13        <cfset croppedImage = imageNew(originalImage)>
14        <!--- Get the coordinates. We will subtract the orinal width minus the new width to grab the center of the new image. --->
15        <cfset xCoordinate = (originalWidth - newWidth) / 2>
16        <cfset yCoordinate = (originalHeight - newHeight) / 2>
18        <cfif debug>
19            <cfoutput>
20                originalWidth: #originalWidth#<br/>
21                originalHeight: #originalHeight#<br/>
22                newWidth: #newWidth#<br/>
23                newHeight: #newHeight#<br/>
24                xCoordinate #xCoordinate#<br/>
25                yCoordinate" #yCoordinate#<br/>
26            </cfoutput>
27        </cfif>
29        <!--- Crop the image. --->
30        <cfset imageCrop(croppedImage, xCoordinate, yCoordinate, newWidth, newHeight)>
32        <!--- And return it. --->
33        <cfreturn croppedImage>
34    </cffunction>

The horizontalCrop, used when we are uploading a portrait image, leaves the width intact, but crops the top and the bottom of the picture equally. This function takes three arguments, the imagePath (or the variable name of the new image when we use the imageNew ColdFusion function), the original height of the uploaded image, and the new height. I am using our ratioCalculator function to provide the new height again while maintaining the original aspect ratio recommended by the social media platform. Again, this example uses the large Facebook size of 1200 for the originalWidth, and 630 for the originalHeight.

view plain about
1<cffunction name="horizontalCrop" access="public" output="true" returnType="string" hint="Used to crop a horizontal image that has a horizontally size that is greater than the desired size of the new image. This will crop the image from the horizontal center.">
2        <cfargument name="imagePath" required="yes" hint="Provide the full original path of the image.">
3        <cfargument name="originalHeight" required="yes" hint="Provide the original width of the image.">
4        <cfargument name="newHeight" required="yes" hint="Provide the desired height of the new cropped image.">
5        <!--- Local debugging carriage. If something goes awry, set this to true. --->
6        <cfset debug = true>
8        <!--- This algorithm was found at --->
9        <cfset originalImage = "#arguments.imagePath#">
10        <!--- Make a copy of the original image. --->
11        <cfset croppedImage = imageNew(originalImage)>
12        <!--- Get the coordinates. The x coordinate starts at 0. The image only needs to be cropped vertically. --->
13        <cfset xCoordinate = 0>
14        <cfset yCoordinate = (originalHeight - newHeight) / 2>
16        <cfif debug>
17            <cfoutput>
18                originalHeight: #originalHeight#<br/>
19                newHeight: #newHeight#<br/>
20                xCoordinate #xCoordinate#<br/>
21                yCoordinate" #yCoordinate#<br/>
22            </cfoutput>
23        </cfif>
25        <!--- Crop the image. --->
26        <cfset imageCrop(croppedImage, xCoordinate, yCoordinate, newWidth, newHeight)>
28        <!--- And return it. --->
29        <cfreturn croppedImage>
31    </cffunction>

This is a rather long and complex post. In my next post, I'll provide some concise examples of social media images that this function creates.

Get the code

The code is published as a git hub repository. This component will also become a part of Galaxie Blog in the next release.

Further Reading

Some of the logic in the center crop function was taken from Raymond Camden's article at

This entry was posted on November 1, 2019 at 1:07 AM and has received 541 views.

How to make the perfect social media sharing image - part 2 Getting the Size Right

There is a lot of information about this on the web- but unfortunately, most of it is wrong or outdated. And this is not necessarily due to the author's mistake. The social media platforms are always fine tuning their image formats and the information changes. To make matters worse, there is conflicting information even when going straight to the source, ie Facebook or Twitter.

For example, here twitter recommends using a 2x1 image ratio1 for their large summary cards, however, twitter has new documentation on it's business page mentioning the new 1.91:1 aspect ratio that was updated this August 2. Faceook is a bit better, but there is an overwhelming amount of information out there, and much of it is confusing. I had to learn the proper aspect ratios by digging into a lot of posts, and through trial and error. I have dug into at least a dozen posts for each image type and this is what I came up with and what proved to work for me best.

The following information should be correct as of October 28 2019. I will periodically try to update this list.

  • Twitter

    • Twitter Summary Card with a large image (1.91:1 aspect ratio):

      • Recommended width: 1200 pixels
      • Recommended height: 628

      • Minimum width: 518
      • Minimum height: 226
  • Facebook
    Facebook has a few more options. There is a large image type, but you can also choose from two different smaller image types. The smaller types allow the text to be floated to the right of the image whereas the larger type puts the text at the bottom underneath a larger image. The aspect ratio for the large image size is just a hair bigger than Twitter's Summary Card.

    • Facebook Shared Image (extremely close to the 1.91:1 twitter format, Facebook has a 1.91 aspect ratio):
      • Recommended width: 1200
      • Recommended height: 630

    • Facebook Link Image - Rectangular
      • Minimum width: 484
      • Minimum height: 252

    • Facebook Link Image - Square
      • Minimum width: 116
      • Minimum height: 116
  • Instagram

    • Recommended width: 1080 (1x1 aspect ratio)
    • Recommended height: 1080

    • Minimum width: 600
    • Minimum height: 315
  • Linked In
    LinkedIn images are very narrow and wide.

    • Recommended width: 1128
    • Recommended height: 376

    • Minimum width: 502
    • Minimum height: 282

If this sounds a little confusing, read on to the next post. In the next post, I will show the actual dimensions of each image type, and provide information how to use ColdFusion to manipulate images to obtain the desired size while keeping the proper aspect ratio.

1A 2x1 aspect ratio is recommended on this particular twitter page "Images for this Card support an aspect ratio of 2:1 with minimum dimensions of 300x157 or maximum of 4096x4096 pixels"
Yet, this twitter page suggests the new 1.91:1 aspect ratio: "Image size: 800 x 418 pixels for 1.91:1 aspect ratio, 800 x 800 pixels for 1:1 aspect ratio"

This entry was posted on October 28, 2019 at 11:21 PM and has received 797 views.

How to make the perfect social media sharing image - part 1 Background

Have you wondered how to get a perfect image from your blog when you share your post on social media? I have... and after spending several weeks on this; I think that I have managed to figure it out...

Over the course of the last few months, I have spent quite a bit of time trying to figure out how to effectively share my content on social media sites. I had thought to simply share the image at the top of each post, but I didn't get the size of the image right. The proper image size was different for each social media platform. Finding the proper sizes between the social media platforms was daunting. The information available on the net is often contradictory, and constantly subject to change. Figuring out the proper approach necessitates aiming at a constantly moving target. What worked several months ago might not work the same now.

After failing at my initial attempt; I reverted the Galaxie Blog code and used the same default social media image that tended to work for every post. While I was sick of looking at the same mountain logo on every social media post (I assume along with my three regular readers), I had more pressing tasks to deal with. There have been a lot of other features that I wanted to put into this blog first, and wanted to wait until I could take a few weeks to devote to learn by trial and error to get this social media image sharing thing right.

There are also other considerations other than just manipulating the image. The social media platforms need to have certain meta tags. After spending the last couple of weeks I found a good approach to solve this. In the next several posts, I will share my journey with you and show you my Galaxie blog implementation. Along the way, I'll provide some ColdFusion scripts for you to resize your own images for social media sharing on your own. Additionally, I hope to provide you some helpful tips.

This entry was posted on October 28, 2019 at 11:29 AM and has received 774 views.

Enabling Search Engine Friendly Links with Url Re-write in Galaxie Blog

I've finally managed to incorporate URL rewrite rules and changed the Galaxie Blog logic to use search engine friendly URL's. Search friendly URL's allow the URL to be more consistent, and eliminate information that is not important. A search friendly URL should easily convey meaning of the page.

Making this open source blog work with search friendly URL's was not a trivial undertaking. A lot of changes had to be made. Galaxie Blog now removes the '/index.cfm' string from the URL. We are also using the posted date and an easy to read entry title within the URL. Galaxie Blog also removes the '/index.cfm' string from all of the links. We don't want to have a mixture of different links that the search engine would crawl and cause duplicate content on several different pages. Additionally, Galaxie Blog will also remove the '/index.cfm' string from both the google site map and RSS feed that Galaxie Blog automatically creates for you.

To enable search engine friendly URL's in Galaxie blog, follow the two steps below.

  1. If you're using IIS, the following rule should be copied and pasted into the web.config in the root directory of the server. The URL redirection rule is between the rewrite tags below. It essentially matches all strings with 'index.cfm', and removes this string. Additionally, it sets a permanent redirect that the search engine uses when crawling your page.

view plain about
1<?xml version="1.0" encoding="UTF-8"?>
3 <system.webServer>
4 <directoryBrowse enabled="false" />
5 <urlCompression doStaticCompression="true" doDynamicCompression="true" />
6        <rewrite>
7        <rules>
8         <rule name="GregorysBlog" stopProcessing="true">
9 <match url="(.*)index.cfm" />
10 <conditions logicalGrouping="MatchAll">
11         <add input="{SCRIPT_FILENAME}" matchType="IsFile" negate="true" />
12 <add input="{QUERY_STRING}" pattern=".+" ignoreCase="false" negate="true" />
13 </conditions>
14 <action type="Redirect" url="{R:1}" appendQueryString="true" redirectType="Permanent" />
15 </rule>
16        </rules>
17        </rewrite>
18 <security>
19 <requestFiltering>
20 <fileExtensions>
21 <add fileExtension=".pl" allowed="false" />
22 </fileExtensions>
23 </requestFiltering>
24 </security>
25 <httpErrors errorMode="Detailed" />
26 <staticContent>
27 <remove fileExtension=".woff2" />
28 <mimeMap fileExtension=".woff2" mimeType="font/woff2" />
29 <remove fileExtension=".webp" />
30 <mimeMap fileExtension=".webp" mimeType="image/webp" />
31 </staticContent>
32 </system.webServer>

  1. In the application.cfc template which is in the blog's root directory, search for the following string and set it to true. It should be around line 22. Note: this is not permanent. You can always reverse this and set it to false at later time if you're new server does not allow for search friendly URL's.

view plain about
1<cfset application.serverRewriteRuleInPlace = true>

That's it! You're blog should now be using search friendly URL's.


  • I especially want to thank Caleb C. from Hostek for helping me get the IIS rule straight. The folks at Hostek have been nothing but outstanding in their service and support!

Further Reading:


  • The search friendly URL features will be available in the next release.

This entry was posted on October 26, 2019 at 5:24 PM and has received 724 views.

Using a dynamic variable to set a dynamic path variable when dropping a cookie

ColdFusion sometimes drives me a bit wonky when I try to set a dynamic variable inside a tag. Most ColdFusion tags support embedded dynamic variables, but quite a few tags don't support this. Probably the most frustrating issue is when you want to use a dynamic variable to extend an application in a sub-folder using two or more application.cfc templates. It seems that every other time I do this I slap my head and think 'Oops! it's time to set up proxy extensions', sigh... but this frustrating issue requires a very long blog entry for a different day. Back to my point...

If you try to use a dynamic variable using a cfcookie tag, you will get the following nasty error:

view plain about
1<cfcookie name="isAdmin" value="true" path="#application.baseUrl#" expires="never">

Attribute validation error for tag CFCOOKIE. It has an invalid attribute combination: expires,name,path,value. Possible combinations are: Required attributes: 'name'. Optional attributes: 'domain,encodevalue,expires,httponly,preservecase,secure,value'. Required attributes: 'domain,name,path'. Optional attributes: 'encodevalue,expires,httponly,preservecase,secure,value'.

To get around this, simply use the cookie scope instead in order to set the dynamic path value.

view plain about
1<!--- Using the cfcookie tag does not work with dynamic vars in the path. --->
2<cfset cookie.isAdmin = { value="true", path="#application.baseUrl#", expires=30 }>

Both cfcookie and the cookie scope do the same thing, send a cookie to the client, but at least the cookie scope allows you to embed dynamic variables for in the path name.

This entry was posted on June 28, 2019 at 12:11 PM and has received 651 views.

ColdFusion error: "The current user is not authorized to invoke this method."

I wanted to document this as this error is not often found using google, but if you receive a ColdFusion error "The current user is not authorized to invoke this method.", it could be due to using the roles attribute in a cffunction tag that don't match the roles that you set using the cflogin tag upon successful login.

I received this error when converting the original application.cfm tag in BlogCfc to use an application.cfc instead. During the conversion processes, I noticed that there was a 'roles' argument on the cffunction that did not match up with the new role that I had just programmed in the cflogin logic. When I searched for this error, I found a bunch of errors relating to using ColdFusions built in administrative user interface, and could not find that it was due to the role restrictions on the cffunction tag and thought to document it. It is a relatively intuitive error, but I am surprised that Adobe did not elaborate and write something like 'The role on the function does not match the cflogin role'. ColdFusion has always been good at that.

If you receive this error, check the roles attributes that you have used. It will likely fix the problem.

This entry was posted on June 2, 2019 at 2:32 PM and has received 1216 views.

Footer Logo

Your input and contributions are welcomed!

If you have an idea, BlogCfc based code, or a theme that you have built using this site that you want to share, please contribute by making a post here or share it by contacting us! This community can only thrive if we continue to work together.

Images and Photography:

Gregory Alexander either owns the copyright, or has the rights to use, all images and photographs on the site. If an image is not part of the "Galaxie Blog" open sourced distribution package, and instead is part of a personal blog post or a comment, please contact us and the author of the post or comment to obtain permission if you would like to use a personal image or photograph found on this site.


Portions of Galaxie Blog are powered on the server side by BlogCfc, an open source blog developed by Raymond Camden. Revitalizing BlogCfc was a part of my orginal inspiration that prompted me to design this site. Some of the major open source contributers to BlogCfc include:

  1. Peter Farrell: the author of 'Lyla Captcha' that is used on this blog.
  2. Pete Freitag: the author of the 'ColdFish' code formatter that is also used on this blog.


Galaxie Blog Version 1.50 November 22 2019