ColdFusion, CSS, and … Football Jerseys?

June 2nd, 2009

I play a little football in my spare time.  It’s not hard core.  In fact, it’s co-ed flag football, but it’s a heck of a lot of fun, good exercise, and surprisingly dangerous. Just like with any group I’m involved with, I see the benefit of getting a website up.  In this case, Excel spreadsheets were being emailed around to a couple hundred people just to get the schedule and stats distributed.  A simple website would solve this.

It didn’t take long to get a quick site thrown together with our schedule, game results, individual stats, and a few photos.

But then I got ambitious.

We are a small league, and most of the players are pretty casual – to the point where many will not remember which team is which.  I wanted to get pictures of the jerseys up on each team page, since many people will remember “Oh yeah, that red team – they’re good”.

Taking pictures of all the jerseys was a start, but cropping jersey pictures did not work well.  I decided to try to “draw” the jerseys in photoshop.  This turned out to be really simple, and I was able to make them look really good.  By the third jersey I realized that I was doing a lot of repetitive work.  I also thought that it may also be cool to put the jersey on each player page as well, with the player’s number superimposed on the jersey.  This would require some CSS to position the number, and some careful font choices.  I wondered what else I might be able to do with CSS.  The logos?  stripes on sleeves?  Wrinkles?  Dirt? Oh yeah.

A long night was ahead.  But this was a mountain I had to climb.

jerseysI started by creating an outline of a football jersey as a mask, leaving the actual jersey portion of the image transparent.  That way if I were to layer the image on top of a div with a solid background colour, it would roughly look right.  I made a portion of the collar semi-transparent to look slightly darker.  These two layers form the bottom (solid colour) and the top (jersey mask) of the stack.  In between, I had to fit the name and number on the jersey (or alternatively, a logo).  The name and number are created with CSS.  The number is easy – a large font centered in the div.

The name is a little more difficult, since really long names require different sizing thn short names.  I solved this by using ColdFusion to calculate the CSS, reducing the font-size of long names, and if necessary, switching to a more narrow font, and reducing the letter-spacing.  For browsers that support the CSS attributes “font-shadow”, I added a bit of depth to the letters to give the illusion that they are stitched on.

For generic team jerseys, a logo can be added to the mix by creating an additional image using the jersey mask as a template, and making sure the image uses the alpha layer to create transparency. With the lettering or logo sandwiched in there, I decided to give the option of stripes on the sleeves or torso, by using CSS to create color blocks.  There can be between 1 and 3 stripes in each position. With my jerseys created, and using my new found skill of making nice transparent PNGs, I tried adding wrinkles to the jerseys.  I created some soft wrinkles using PNG files, and layered them on top of everything.  This gave the jerseys way more life, and they now did not look as fake.

Unfortunately the transparent PNG technique does not work in IE6/ IE7, and using a GIF in that case just looked like crap, so too bad for the IE crowd. They still get the jerseys, just no extras.  I also made some PNG files to create the effect of dirt on the jerseys.  I use these for jersey images in game summaries, since a clean jersey usually means you didn’t play too hard.  Instead of a generic dirt image, I made 5 different ones, which are assigned at random, so that each jersey does not have the same dirt pattern. With that, I was satisfied.  The jerseys look really good, and the code allows an endless combination of colours for the teams that like to show up with new jerseys each year.  If a team needed a new logo, I could create one easily, and apply it to the jersey.

Jersey Showcase Page

Zip Download

The code is pretty simple.  As long as you load the jerseys.cfc file somewhere in your page (or application scope) you can call the jersey generator with the following code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<cfscript>
	jStr = structnew();
	jStr.team_key = 'steamers'; // this loads the logo file if logo is 1
	jStr.size = 200;  // size of jersey (400/200/100/40)
	jStr.colourA = '33CC00'; // main jersey colour
	jStr.colourC = 'fff'; // numbers and middle stripe colour
	jStr.colourB = '333'; // outer stripe color
	jStr.displayName = 'mallinson'; // jersey name
	jStr.displayNumber = '23'; // jersey number
	jStr.sleeveStripes = '1'; // amount of sleeve stripes
	jStr.torsoStripes = '3'; // amount of torso stripes
	jStr.dirty = 1; // 1 = dirty, 0 = clean
	jStr.logo = ''; // '' = no logo, '1' = load logo
</cfscript>
<cfoutput>
#jerseys.displayJersey(argumentcollection=jStr)#
</cfoutput>

I wrote all of this last summer, and I’m bringing the code back now because I have some plans to use the jersey generator in a project I’m working on. I have big plans for the code as well. I’m going to make it useful for baseball jerseys, hockey jerseys, and basketball jerseys, as well as add some more features that take advantage of CSS3.

And one more thing. The generated code is not very semantic – and that normally just kills me. But this is for fun, and for my purposes, there’s no need for perfect code in this case. When I roll this out as a part of a bigger project though, I will output a very simple bit of code to the browser that just gives the player’s name and number. Then through the magic of jQuery, I’ll “progressively enhance” the code to display the jersey via DOM manipulation. But that is another day. I’ll release that code in the future – when it is written.

Bolt Action?

June 1st, 2009

Adobe really needs to get this right.  Bolt, the soon to be released IDE for ColdFusion, is the talk of the town in the CF community, and let me tell you – it better be good.  I have to say, I’m not really that pleased that this is an Eclipse based product.  I’ve almost completely dropped Eclipse lately due to instability – at least on the Mac.  I think that Adobe could have made this product a stand-alone product on its own platform, and still allowed it to be extensible  (If you have not heard, you will be able to write extensions for Bolt with CFML, which is all kinds of awesome).

Read the rest of this entry »

Taking a Pass on Flex

May 19th, 2009

Am I the only one who just doesn’t understand why so many ColdFusion developers are jumping to Flex? I’m aware that my opinion on Flex and its place may be unpopular in the ColdFusion community, but I’m wiling to entertain the possibility that I may be wrong, so bear with me.

I’ve taken in all the Flex coverage and sessions at CFUnited and MAX, and I’ve attended full day workshops on Flex more than once. Don’t get me wrong, I’ve been nothing but impressed with the capabilities of the platform, and pleased that Adobe has made everything work so well with ColdFusion. I just don’t like the end product of most sites built in Flex. I am most impressed with sites that use nice clean markup and unobtrusive JavaScript for progressive enhancement. Whenever I visit a Flex site, it feels like I’m using someone else’s computer. You know that feeling? for me it’s the fact that usually, my MacBook Pro’s trackpad scrolling will not work with the Flex scroll-bars. Not a huge deal, but it makes a difference.

One of the big advantages of using Flex is not having to worry about testing in multiple browsers. I believe over 99% of people can access your Flex site with their existing version of Flash. This is a great benefit, but it’s not as big of a deal as it was a few years ago. Today, the biggest problems are still with IE6, and for many sites I’m happy providing decreased functionality for those users. Using jQuery also eliminates a large amount of JavaScript incompatibility between browsers.

There is a market for Flex, and I think that market will continue to grow. I’m also pleased that Adobe has embraced it, since it adds a perfect piece to their product suite. I just don’t like the whole “If you’re not jumping on the Flex bandwagon, you’re missing the boat” mentality that I hear a bit too much in the ColdFusion community. I hope that Adobe continues to support and enhance the capability of ColdFusion to work with HTML based content.

Moving to WordPress

May 18th, 2009

I’ve always thought that as a ColdFusion developer, I should use CF for my own site. It wasn’t even something I’d thought about. I’ve used both BlogCFC and Mango Blog for my own site, and still use both on various other sites. I’ve been really happy with both, and have no plans to swap them out on any other sites.

I found it really easy to add all kinds of functionality using ColdFusion as a blogging platform, and that’s why I’ve stuck with the CF blogs so far.  But then I did a little work on my cousin’s blog last year (check it out if you like illustration), and was intrigued.  Since then, WordPress has made a bunch of updates, and the admin interface is simply beautiful.  I found a very simple template, made some changes to the CSS, and everything worked.  My last step is usually to bite the bullet and open up my new sites in IE6 – to see how late I will be up fixing it.  For the first time ever, I had absolutely nothing to fix.  I know this is due to the good work of the template designer, and not necessarily WordPress, but it speaks to the magnitude of people working on this platform.

I still think ColdFusion is the best platform for a ton of things, and personal sites may be one of those things.  As a developer though, I can appreciate the amount of work that has been put into WordPress, and when a piece of software fits your needs so perfectly, it’s hard (and irresponsible) to ignore it.  The reason I love WordPress is the same reason that I love Macs.  They just work, and they look great.  It may seem silly that the look of the admin interface is so important to me, but if I need to look at something every day, I like it to look good.

I must say that I’ve got a bit of guilt about this.  I almost feel that I’m betraying the CF developers that have put work into open source applications that come close to meeting my needs.  There are still plenty of CF open source applications that I use daily and support, and I don’t see that changing.

URL Trimming in Mango Blog

April 24th, 2009

Instead of using all the URL shortening services out there, I thought it would be just as easy to write my own, and retain my own domain in the URL. My domain name is not that short, but since I would only be using it to redirect to my own pages, I would only need a few characters to create the links. I use Apache as a webserver, and Mango Blog as an engine. This method, however, also works with BlogCFC, another popular, and awesome, ColdFusion blog engine. Both these blog engines use UUIDs as primary keys in the blog entry tables. I added an integer field in the entry table called “pk”, and made it the primary key with auto-increment turned on. This gives all your blog entries a numeric index. The next step is to create a file somewhere on your site with some code to redirect requests that use your URL shortening service. I called it trimURL.cfm:

1
2
3
4
5
6
7
8
9
10
11
<cfquery name="getURL" dataSource="mallinson">
  SELECT    name
  FROM 	 entry
  WHERE	 pk = <cfqueryparam CFSQLType="CF_SQL_VARCHAR" value="#url.id#" />
</cfquery>
 
<cfif getURL.recordcount>
	<cflocation addToken="no" url="http://mallinson.ca/post/#getURL.name#" />
<cfelse>
	<cflocation addToken="no" url="http://mallinson.ca" />
</cfif>

With this code, this blog entry can be referenced by visiting http://mallinson.ca/12. The next step requires that you know a bit about Apache Web Server, or are familiar with URL rewriting using another type of web server. I use Apache, and URL Rewrite. In my .htaccess file, I have a lot of entries that clean up my URLs, but I’ll isolate the one rule that makes the URL rewriting work.

RewriteEngine On
RewriteRule ^([0-9]{1,6})$ trimURL.cfm?id=$1 [L]

What this bit of code does is take any URL that is composed entirely of digits, up to 6 digits (I don’t anticipate breaking a million posts), isolate the digit, and pass it to my redirecting page. I intend to register another much shorter domain as soon as I find something good. Then I could get the URL strings down to 10 characters or so.

My Mac Mini @ Macminicolo

April 20th, 2009

There are thousands of web hosting / co-location services out there, but as far as I know, there are none that will co-locate a server that can be shipped in a shoebox, and will treat it like it belongs in a rack, next to the big boys.

Macminicolo.net does just that.  You send them a Mac Mini (or buy one from them at the going rate) and they will hook it up to a smoking fast connection in a managed facility.  You get full access to your machine, and can even (optionally) manage the power supply remotely.

Worried a Mac Mini would not be able to keep up with your needs?  You’d be surprised.  They perform very well under load, especially maxed out with RAM.  In addition to being able to host unlimited domains yourself, it’s a great way to keep remote secure backups, manage an SVN repository, or just to use as a personal file server.

I’ve been using their service for about a year, and I’m extremely satisfied.

Bio

A Web Developer in Vancouver who has been playing with computers since the dawn of time.