rTraction

Viewing posts by: Gavin Blair

Feature Ribbons with PHP and GD

September 21, 2010

Written by | No Comments



Adding a diagonal ribbon to a thumbnail is easy with PHP and GD. You may be able to accomplish this task with CSS3, but the result can be a little buggy (strange wiggles on mousover), and it currently is not consistent across browsers. You can create dynamic images in PHP using GD functionality.

The Ribbon Base Image

The ribbon base image that I use is not a transparent PNG – rather, behind the red banner I have a pink background. In PHP we will tell GD to interpret pink as transparent so that our edges are smooth. Feel free to use this image for your own purposes.

Using GD to Add Text

This file will take the base image and place white text over it. Now we can treat this file as an image, and include it in our CSS or image tags. Note that this file refers to arial.ttf – this font file (or whatever TTF font file you decide to use) must be in the same directory as ribbon.php. You can find arial.ttf in your computer’s fonts directory.

Usage

The important part here is the background-image. Notice how the text we want is in the query string of ribbon.php.

Styling and Position

This will place the ribbon in the lower right corner, above the image.

Questions, comments or optimizations? Let us know in the comments.

I Less Than Three My Job

May 17, 2010

Written by | 1 Comment



My biggest fear upon leaving university was that I would get stuck at a place like Initech;  that my best days were behind me and it was now time to start the grown-up process of working to pay for all of the fun from my youth.

My experience at rtraction has been far from that.  I have a say here  and my ideas matter. rtraction is more than a web development shop, it’s also a place where really neat things get created. It’s also a place where one can say “really neat” and not get beat up. Definitely better than school.

Here are just a few of the really neat projects that make this the best job ever.

NeedVision

Last July I had the opportunity to mashup Google Maps and back then, the fancy new  Kiva API to create a slick new way to look for microlending opportunities.

NeedVision shows you available Kiva loans on a map of the world. It’s also open source. If you can make NeedVision better, do it. Then tell us about it :)

1000 Acts of Kindness

1000 Acts of Kindness, aside from being a great Corporate Social Responsibility project, is a very cool website from a technical perspective.

In November I was tasked with making the front page of the website into something really cool. I had been looking for an opportunity to put the parallax effect into practice, and this was perfect.

Compost

Compost has been my pet open-source project since late last year. It allows designers to gather feedback from their clients, in a graphically appealing and intuitive way.

For more information about Compost and how you can get involved, check out compo.st. An iPhone version is in the works, and a BlackBerry version is currently being planned by a member of the local development community.

PolicyTool

In collaboration with technology lawyer David Canton of e-Legal, we rolled out PolicyTool. PolicyTool lets you fill out a simple questionnaire and then generates a policy based on your answers.

Since its March release, PolicyTool has made a nice splash in the social media scene. It is very nice to be able to say that you’ve been part of something that went viral.

LondonFUSE Code Blitz

One day in March, the dev team worked collaboratively to build our first iPhone app for London Fuse. In eight hours we had a working version of the app that listed upcoming events in London Ontario.

If you have tried the app and would like to make a suggestion for the next version, check out LondonFUSE on uservoice.

eatsure and Open Data

Encouraging the city to open more data, Noah Stewart, David Millar and Shawn Adamsson created eatsure.ca using data from the local health unit’s Food Inspection Disclosure Site.

This is very exciting – as more data becomes available, the more really cool projects we get to create.

Podcamp London Twitter Visualization

The most recent supercool project that I had the privilege of working on was the Podcamp Twitter visualization. In addition to CodeIgniter, jQuery, and the Twitter API, the project makes use of clever CSS3 transformations to create a 3D effect.

Corporate Social Responsibility

Everyone at rtraction has the opportunity to take some time every month for a CSR project. Past projects include 1000 Acts of Kindness and Reforest London. This is an excellent opportunity to get connected to the community and use our powers to do good.

Office Pranks

As with any office, pranks happen every once in a while. I don’t mean to boast, but my latest masterpiece in this area has left others… speechless. What can I say? Pranking one officemate while framing another and simultaneously preventing revenge because the prank was officially a “good deed” – priceless.

Now, look at your job. Now look at my job. Look at your job, then back to my job. Sadly, your job is not my job. But it can be, because we’re hiring!

If you have any questions about the job posting or any of our projects, ask away in the comments section below.

Isometric 3D Effect with CSS3 Transformations

May 12, 2010

Written by | 5 Comments



I recently had the opportunity to make use of CSS3 transformations to achieve a 3D effect in a practical application.

If you’re a web developer reading this, you know that something like this doesn’t happen every day, and is therefore very exciting!

The main requirement for the project was to display a 3D isometric floorplan of the Convergence Centre at Western University in London Ontario, with tweeps showing up in the room they are tweeting from.

Each room is a <div class=”users”> that can contain <div class=”avatar”> as many times as needed. Transparent GIF’s are used as background images for the character’s body, head, torso and legs.

<div id="bar" class="users">
	<div class="avatar">
		<div class="head"></div>
		<div class="torso"></div>
		<div class="legs"></div>
	</div>
	<div class="avatar">
		<div class="head"></div>
		<div class="torso"></div>
		<div class="legs"></div>
	</div>
</div>
<div id="maple" class="users">
	<div class="avatar">
		<div class="head"></div>
		<div class="torso"></div>
		<div class="legs"></div>
	</div>
</div>

For development purposes, we put a thick red border around the rooms.
As we add more avatars to a room, we’ll adjust their margins so that characters squeeze closer together and the room will not overflow.
Avatars are floated right so they stack nicely – closer ones will overlap farther avatars.

.users {
	border: 4px dashed red;
	position: absolute;
}
.users .avatar {
	height: 44px;
	width: 33px;
	float: right;
	margin: 17px;
	position: relative;
}
.head, .torso, .legs {
	position: absolute;
	top: 0;
	left: 0;
	height: 44px;
	width: 33px;
}

Adding CSS3 transformations, we can skew the room divs to match the shape of the rooms in the background image.
The side-effect of this is that the avatars inside will also be skewed.
The CSS below will affect Mozilla and Webkit-based browsers only.

.users {
	border: 4px dashed red;
	position: absolute;
	-moz-transform: skewX(45deg) skewY(-12deg);
	-webkit-transform: skewX(45deg) skewY(-12deg);
}

Now we have to put an opposite skew on the avatars to cancel out the room skew.

.users .avatar {
	-moz-transform: skewX(-50deg) skewY(12deg) scaleX(1.2);
	-webkit-transform: skewX(-50deg) skewY(12deg) scaleX(1.2);
}

All that’s left is to remove the red border around the rooms!

If you have any questions or comments about using CSS3 to achieve a 3D effect, or if you want to show off your own 3D CSS3 project, we’d love to hear from you!

Ewoks at Podcamp London

May 12, 2010

Written by | 4 Comments



Ewoks was the codename of our Twitter display at last Saturday’s Podcamp London. The purpose of the application was to provide a fun interface to view tweets that pertained to the event throughout the day. The application provided event attendees with useful information and a new way to interact with others.

Features

Response

Attendees found this display to be very useful – they would see tweets of someone they know enjoying a session in one of the rooms, and they would make the decision to visit that session. Some users managed to find an “easter egg” built in – when a user uses the hash tag “#bye” their avatar would be beamed off the map with an animated laser.

Throughout the day people congregated in front of the display to check out what others were saying and what was coming up next, or to find directions.

Built on Code Igniter, the application made use of jQuery, CSS3 transformations (to achieve a 3-dimensional effect) and the Twitter Search API. Stay tuned for a more technical post on how some of the effects were achieved.

Lessons Learned

You can do amazing things with Javascript and CSS – Flash is no longer the only option for “cool”. Since this application was meant to run on a large display there was no need to worry about browser consistency which allowed for unbridled CSS3 greatness!

Seeing others interact with your work is very rewarding. Seeing large groups of people, mobile devices in hand, staring at the screen waiting for their tweet to show up or their character to blow up makes it all worthwhile.

If you have any questions or comments about Ewoks (the application, not the small furry creature indigenous to the forest moon of Endor), or if you have built your own supercool Twitter display, we’d love to hear from you!

Extending the Controller Class in CodeIgniter

March 11, 2010

Written by | 10 Comments



CodeIgniter is a great little PHP framework that allows you to rapidly build MVC web applications. Without getting too far into Model View Controller ideology, this post will explain how to extend CodeIgniter’s Controller class to achieve site-wide authentication checks.

Not long after starting your fancy new webapp, you will start to realize that putting

if (!isset($_SESSION['isloggedin'])) {
  redirect('/login');
}

in every single controller function is very tedious.

You can create an extension of the Controller class and put the common code in there. Here’s how.

Create a file in /system/application/libraries called MY_Controller.php. The name of this file is important. If the prefix “MY_” doesn’t do it for you, go into /system/application/config/config.php and change

$config['subclass_prefix'] = 'MY_';

to whatever you want. Don’t change the “Controller” part though! You can also extend Models and Helpers.

Start with the following code in MY_Controller.php:

class Authenticated_Controller extends Controller {
  function Authenticated_Controller() {
    parent::Controller();
    session_start();
    if (!isset($_SESSION['isloggedin'])) {
      redirect('/login');
    }
  }
}

Go ahead and add any common controller functions to this class. Feel free to change “Authenticated_Controller” to whatever you want. You can also have multiple Controller extensions in this file.

Note: If you only have one controller extension, it is standard to name your class MY_Controller (rather than Authenticated_Controller).

Important Note: If you find yourself creating a bunch of controller extensions, take a step back and consider what you are doing. Is your extension being used by only one controller? If so, just put your code in that controller’s constructor.

Now it’s time to start using your new controller extension!

In every controller that requires authentication (don’t do this for your login controller!) rather than the traditional

class Manage extends Controller { ...

use this instead:

class Manage extends Authenticated_Controller { ...

Do you have CodeIgniter controller extensions that could be useful to others? Let us know in the comments.