Posts Mentioning RSS Toggle Comment Threads | Keyboard Shortcuts

  • Andy P 5:55 pm on August 16, 2008 Permalink | Reply
    Tags: , slides,   

    Here are my slides from WordCamp and also the links from the last slide. I hope you enjoyed the talk, Matt makes presenting look so easy, but it’s pretty tough once you actually get up there! The feedback was great, and I’m glad people enjoyed learning about BuddyPress.

    Slides:
    http://www.slideshare.net/apeatling/buddypress-wordcamp-presentation

    Links:
    – BuddyPress Testdrive: http://testdrivewpmu.com
    – BuddyPress Website: http://buddypress.org
    – SVN: http://svn.buddypress.org/trunk
    – Mailing List: http://tinyurl.com/6ee7jo
    – IRC: #buddypressdev (Freenode)
    – Twitter: @buddypressdev
    – Screenshots: http://tinyurl.com/657ycl

     
  • Andy P 12:49 pm on August 8, 2008 Permalink | Reply
    Tags: , conferences, fpdf, gravatars, , scripts,   

    For the first time this year, WordCamp San Francisco conference badges will include your gravatar. Adding photos to conference badges is nothing new, however bringing your online gravatar into the offline world is a fairly exciting move.

    I’d like to share how I created the PHP script to generate the badges. I hope people can re-use the script for future WordCamps, or even any other conferences. If you want to skip the tutorial and just download the script, here it is. I’ve released it under the GNU/GPL 2 license.

    Step 1: The FPDF library

    The FPDF library is a free to download and use, open source library that will generate PDF files without the need for any specific PHP libraries. The nice thing about it is the documentation is easy to read and has good examples.

    Head on over and download the library. You’ll want to create a new directory to store everything in. I called mine “badge-gen” but you can call it whatever you like. Extract the FPDF library into a folder called “fpdf” in the root of your main directory.

    Step 2: Create the generation script and include everything we need

    Create two new PHP files in the root of your main directory and call one “generate.php” and the other “functions.php”. In the generate.php file we need to require everything we need to set up the environment:

    <?php
    require('fpdf/fpdf.php'); // require the FPDF library
    require('functions.php'); // require the functions we are going to use
    ?>
    

    Step 3: Add image manipulation and download functions

    In the functions.php file, we need to add two image manipulation functions and a function to fetch and download gravatars. The first image function will detect the file extension for an image, and the second will convert PNG files to JPG files. Identicons are PNG files with alpha transparency, unfortunately FPDF does not support alpha enabled PNG images, so we need to convert them to JPG images on the fly. You will need the GD image library installed with PHP on your server.

    Add these functions to functions.php:

    <?php
    function get_file_by_curl( $file, $newfilename ) {
        $out = fopen( $newfilename, 'wb' );
        $ch = curl_init(); 
    
        curl_setopt( $ch, CURLOPT_FILE, $out );
        curl_setopt( $ch, CURLOPT_HEADER, 0 );
        curl_setopt( $ch, CURLOPT_URL, $file ); 
    
        curl_exec( $ch );
        curl_close( $ch );
    }
    
    function get_image_extension($filename) {
    	$type_mapping =  array( '1' => 'image/gif', '2' => 'image/jpeg', '3' => 'image/png' );
    	@$size = GetImageSize( $filename );
    
    	if ( $size[2] && $type_mapping[$size[2]] ) {
    		if ( $type_mapping[$size[2]] == 'image/gif' )
    		        return '.gif';
    
    		if ( $type_mapping[$size[2]] == 'image/jpeg' )
    			return '.jpg';
    
    		if ( $type_mapping[$size[2]] == 'image/png' )
    			return '.png';
    	}
    	return '.jpg';
    }
    
    function pngtojpg( $file ) {
    	if ( get_image_extension( $file ) == '.png' ) {
    		$image = imagecreatefrompng( $file );
    		imagejpeg( $image, $file . '.jpg', 80 );
    		return $file . '.jpg';
    	} else {
    		return false;
    	}
    }
    ?>
    

    Step 4: Add image download and template directories

    We’ll need to make use of a few images for the badges. The entire background on the WordCamp badges is an image. Try and make your images 300dpi, and then scale them down to the size you need in the code. This will ensure that each badge prints in good quality, and doesn’t come out as a pixelated mess.

    Store all your images in an “/images” directory in the root of your main folder. This example only includes one static image, the background we just mentioned. You can download the file here.

    Due to the way that gravatar image URLs work (they don’t have any sort of file extension and are just a URL with GET variables and an MD5 of your email) we will need to download them before we can add them to badges. This is a limitation of the way images are used in the FPDF library.

    Create another directory within your “/images” directory and call it “temp”. You will need to make this directory writable by the server, so either “chmod 777 temp” or use your FTP app to set the permissions. This is where gravatars will be downloaded and stored. If you forget to set the permissions on this folder, you will see a bunch of garbage text on the screen when you try and generate the badges (just a warning).

    Finally, create a “/templates” directory in the root of your main folder. In this folder you can store badge page layout templates. For this example we will use a template for Avery Pin Style Name Badges 74549. If you need to use a different template, duplicate this file and make the modifications to the co-ordinates. I’d be happy to create a place to share layout templates if people let me know where to find them.

    FPDF treats each PDF page as a canvas, where you set every item’s position using co-ordinates. The co-ordinate values represent millimeters allowing you to measure a normal sheet of paper to get badges positioning perfectly.

    In your templates directory, create a new file called “avery74549.php” and add the following code:

    <?php
    // Add a page, but only on a multiple of 9 (as there are 8 badges per page)
    if ( $counter == 1 || ( $counter % 9 == 1 ) ) {
    	$pdf->AddPage('P', 'Letter');
    	$counter = 1;
    }
    
    // Set the co-ordinates for all items in each of the badges
    switch ( $counter ) {
    	case 1:
    		$background_x = 12.5;
    		$background_y = 22;
    		$avatar_x = 81;
    		$avatar_y = 28;
    		$text_x = 17.5;
    		$text_y = 52;
    	break;
    	case 2:
    		$background_x = 108.5;
    		$background_y = 22;
    		$avatar_x = 177;
    		$avatar_y = 28;
    		$text_x = 114;
    		$text_y = 52;
    	break;
    	case 3:
    		$background_x = 12.5;
    		$background_y = 83;
    		$avatar_x = 81;
    		$avatar_y = 88;
    		$text_x = 17.5;
    		$text_y = 113;
    	break;
    	case 4:
    		$background_x = 108.5;
    		$background_y = 83;
    		$avatar_x = 177;
    		$avatar_y = 88;
    		$text_x = 114;
    		$text_y = 113;
    	break;
    	case 5:
    		$background_x = 12.5;
    		$background_y = 144;
    		$avatar_x = 81;
    		$avatar_y = 150;
    		$text_x = 17.5;
    		$text_y = 174;
    	break;
    	case 6:
    		$background_x = 108.5;
    		$background_y = 144;
    		$avatar_x = 177;
    		$avatar_y = 150;
    		$text_x = 114;
    		$text_y = 174;
    	break;
    	case 7:
    		$background_x = 12.5;
    		$background_y = 205;
    		$avatar_x = 81;
    		$avatar_y = 211;
    		$text_x = 17.5;
    		$text_y = 235;
    	break;
    	case 8:
    		$background_x = 108.5;
    		$background_y = 205;
    		$avatar_x = 177;
    		$avatar_y = 211;
    		$text_x = 114;
    		$text_y = 235;
    	break;
    }
    ?>
    

    Step 5: The Beef

    Now we have the environment set up, we can move on to the actual generation of the badges.

    Open up your “generate.php” file, as this is the file we are going to edit from now on. The first step is to instantiate the FPDF class and store it in the object variable “$pdf”. Add the following below the existing code:

    // Set up the new PDF object
    $pdf = new FPDF();
    
    // Set the text color to white.
    $pdf->SetTextColor(255,255,255);
    
    // Remove page margins.
    $pdf->SetMargins(0, 0);
    
    // Disable auto page breaks.
    $pdf->SetAutoPageBreak(0);
    

    Now we need to retrieve attendee information from somewhere, and load that into an array. You could query a database to retrieve this information, or you could hard code it into the file. You will need the attendees’ first name, last name, email address and optionally their blog URL.

    For the sake of this how-to, we will hard code a couple of attendees into an array to use.

    // Grab the attendee list
    $attendees = array(
       array( 'first_name' => 'John', 'last_name' => 'Smith', 'email' => 'john@smith.com', 'blog' => 'http://john.smith.com' ),
       array( 'first_name' => 'Jane', 'last_name' => 'Doe', 'email' => 'jane@doe.com', 'blog' => 'http://jane.doe.com' ),
       array( 'first_name' => 'Kris', 'last_name' => 'Masters', 'email' => 'kris@masters.com', 'blog' => 'http://kris.masters.com' )
    );
    

    Now we have the attendee array set up, we can loop through each one and write each value to a badge in the PDF file:

    // Loop through each attendee and create a badge for them
    for ( $i = 0; $i < count($attendees); $i++ ) {
    		// Grab the template file that will be used for the badge page layout
    		require('templates/avery74549.php');
    
    		// Download and store the gravatar for use, FPDF does not support gravatar formatted image links
    		$grav_file_raw = 'images/temp/' . $attendees[$i]['first_name'] . '-' . rand();
    		$grav_data = get_file_by_curl( 'http://www.gravatar.com/avatar/' . md5($attendees[$i]['email']) . '?s=512&default=identicon', $grav_file_raw );
    
    		// Check if the image is a png, if it is, convert it, otherwise add a JPG extension to the raw filename
    		if ( !$grav_file = pngtojpg($grav_file_raw) ) {
    			$grav_file_extension = get_image_extension($grav_file_raw);
    			$grav_file = $grav_file_raw . $grav_file_extension;
    			rename( $grav_file_raw, $grav_file );
    		}
    
    		// Add the background image for the badge to the page
    		$pdf->image('images/back.jpg', $background_x, $background_y, 96, 61);
    		$pdf->image($grav_file, $avatar_x, $avatar_y, 21, 21);
    
    		// Set the co-ordinates, font, and text for the first name
    		$pdf->SetXY($text_x, $text_y);
    		$pdf->SetFont('helvetica','b',33);
    		$pdf->MultiCell(86, 13,ucwords(stripslashes($attendees[$i]['first_name'])),0,'R');
    
    		// Set the co-ordinates, font, and text for the last name
    		$pdf->SetXY($text_x, $text_y + 11);
    		$pdf->SetFont('helvetica','',16);
    		$pdf->MultiCell(86, 13,stripslashes(ucwords($attendees[$i]['last_name'])),0,'R');
    
    		// Remove http:// from blog URL's and also remove ending slashes
    		$attendees[$i]['blog'] = str_replace('http://', '', $attendees[$i]['blog']);
    
    		if ( $attendees[$i]['blog'][strlen($attendees[$i]['blog']) - 1] == '/' )
    			$attendees[$i]['blog'][strlen($attendees[$i]['blog']) - 1] = '';
    
    		// Set the co-ordinates, font, and text for the blog url
    		$pdf->SetXY($text_x, $text_y + 17);
    		$pdf->SetFont('helvetica','',10);
    		$pdf->MultiCell(86, 13,$attendees[$i]['blog'],0,'L');
    
    		$counter++;
    }
    

    Finally once we have looped through all attendees and added a badge for each, we can output the PDF file to the browser so it can be saved or printed:

    // Output the PDF file to the browser
    $pdf->Output();
    

    That’s it! You can download the final source files here. Good luck creating gravatar enabled badges. Please ask any questions in the comments, or post links to show off your own conference badges.

     
    • sibirya 5:23 am on August 11, 2008 Permalink | Reply

      I have gravatar

    • Raul 8:54 pm on August 13, 2008 Permalink | Reply

      Andy,

      Can this code be used to generate the badge for any other conference? If so, and if we actually manage to start WordCamp BC (as Kulpreet had suggested) maybe we could generate badges using this code?

    • max 3:58 am on September 5, 2008 Permalink | Reply

      i have to install it on my blog

    • Elad Salomons 11:30 pm on October 22, 2008 Permalink | Reply

      Hi,
      Thanks for the code. I have just created you an Hebrew name badge with the WordCamp Israel 2008 template.

    • wolly 1:44 pm on November 25, 2008 Permalink | Reply

      thanx a lot for yours script.
      I’m going to try to integrate it in wordpress for wordcamp.it, if I succed I’ll publish the code.
      ciao

    • Andy P 3:25 pm on November 25, 2008 Permalink | Reply

      Glad to see lots of people making use of this script! Please do release any updates you make to the code.

    • wolly 6:56 pm on November 25, 2008 Permalink | Reply

      Andy I’ll write a tutorial to use it directly in wordpress , I have decided this year to use only wordpress for the wordcamp, registration, list of speech, list of campers and now the badge :-)
      It will be mine speech for wordcamp.it, How to use and customize wordress to manage an event. :-)
      thanx a lot

    • wolly 7:13 pm on November 25, 2008 Permalink | Reply

    • Frosty 7:11 pm on September 11, 2009 Permalink | Reply

      Used it for WordCampLA: WordCampLA Name badge

  • Andy P 12:07 am on August 6, 2008 Permalink | Reply
    Tags: , gravatar, identicon, ,   

    Update: If you are attending, check your badge here!

    WordCamp San Francisco 2008 badges will include gravatar images, so make sure you have your gravatar set up before August 14th.

    Gravatars now support resolutions up to 512×512 pixels. The higher resolution your gravatar image is, the better it will look on your badge.

    For those attendees without a gravatar, an identicon will be included on your badge.

    I’m excited to see these in print, I think gravatars will add a really nice touch to the badges, and it also shows they are useful even in the offline world.

    I’ll be writing a tutorial on how to generate gravatar enabled conference badges very soon.

     
    • Raul 2:04 am on August 6, 2008 Permalink | Reply

      Um, I know the geek showing in that Gravatar. Wait… yes I do, it’s my friend Andy! :)

    • Joseph Scott 2:42 am on August 6, 2008 Permalink | Reply

      Would be really nice if there was a way to see a preview of the badge before hand. That will give me chance to upload a higher quality image if my current one doesn’t look so great.

    • litwc 3:15 am on August 6, 2008 Permalink | Reply

      Well I changed my favicon based gravataar to a photo… just for this. (And yes the post is a test.

    • Mark Jaquith 3:40 am on August 6, 2008 Permalink | Reply

      Looks like best results come from uploading a 512×512 image.

      Any way you could (without violating your privacy policy) automatically e-mail any WordCamp attendees who don’t have a 512×512 Gravatar? For instance, Joseph, your Gravatar is an old 80×80 one, so it looks like a mosaic at 512×512.

    • aw 7:41 am on August 6, 2008 Permalink | Reply

      I hope everybody can get a gravatar !!! :)

    • Dustin 10:16 am on August 6, 2008 Permalink | Reply

      You’re so darn cool, Andy! Great idea!

    • willandbeyond 1:50 pm on August 6, 2008 Permalink | Reply

      No WordCamp for me, but great idea, and glad to hear about the jump to 512px!

    • DeL 4:06 pm on August 6, 2008 Permalink | Reply

      yeah it will be cool , can’t wait to hear your tutorial on this gravatar

    • Andy 4:25 pm on August 6, 2008 Permalink | Reply

      @Joseph: I’ve come up with a new avatar checker so you can see what your badge will look like.

    • Andrea 5:54 pm on August 6, 2008 Permalink | Reply

      Dang, I wish I could be there. I think this is a brilliant idea, especially since personally I can’t remember names very well, but I instantly remember faces – or in this case, people’s gravatars.

    • moneymingle 7:06 pm on August 6, 2008 Permalink | Reply

      Hopefully will be recorded! I think many avatars can become a part of your overall branding strategy.

    • Mark Jaquith 8:04 pm on August 6, 2008 Permalink | Reply

      Why isn’t mine working? I have a Gravatar set up for my PayPal address but it’s showing as an Identicon. I created the PayPal address Gravatar after registering. Are you using some sort of caching system?

    • Mark Jaquith 8:07 pm on August 6, 2008 Permalink | Reply

      Ah, because it’s not using the PayPal e-mail address, but the one provided in the registration form. Good to know!

    • Jeffro2pt0 10:02 pm on August 6, 2008 Permalink | Reply

      Damn, WordCamp San Francisco is the grand daddy of all WordCamps. Really wish I could attend this event but alas, I’ll have to wait till next year maybe.

    • United Voices 3:22 am on August 7, 2008 Permalink | Reply

      He he … i’ve my gravatar alreay ready.

    • Mostly Lisa 5:41 am on August 7, 2008 Permalink | Reply

      i got a gravatar like a year ago when it was cool to like, universally identify yourself on the interweb. now, i’d like to be addressed as the skype emoticon combo (emo) + (poolparty). i’m just waiting for the rest of the www to step in line.

    • inna 11:00 am on August 11, 2008 Permalink | Reply

      hi, this is cool but i feel left out, as my gravitar does not show up on the badge.

    • arama motoru 10:02 am on November 10, 2008 Permalink | Reply

      thanks.

    • mobilya 2:44 am on December 2, 2008 Permalink | Reply

      thanks..

    • vidanjör 2:41 am on December 15, 2008 Permalink | Reply

      thnaks..

    • izmir çiçek 7:52 am on December 16, 2008 Permalink | Reply

      thanks for sharing..

    • izmir evden eve 12:43 pm on January 7, 2009 Permalink | Reply

      thanks you.

    • malzemeleri 11:56 am on January 15, 2009 Permalink | Reply

      thanks..

    • indirimli alışveriş 4:22 am on January 23, 2009 Permalink | Reply

      thanks you…

    • sibelimss 12:57 pm on February 4, 2009 Permalink | Reply

      thanks you..
      duşakabin
      raydolap

    • john 11:08 am on February 9, 2009 Permalink | Reply

      interesting new development in the upcoming WordCamp—WordCamp San Francisco, that is. Camper badges will use the gravatars of the registered

      ı like very much

    • raylı dolap 7:13 am on February 24, 2009 Permalink | Reply

      Thanks

    • büro mobilyaları 3:53 am on February 26, 2009 Permalink | Reply

      thanks you..

    • büro mobilyaları 9:50 am on February 27, 2009 Permalink | Reply

      thanks for sharring

    • bursa evden eve nakliyat 5:18 am on February 28, 2009 Permalink | Reply

      thanks you

    • belek golf 10:07 am on March 1, 2009 Permalink | Reply

      Thank You..

    • dinleme cihazı 5:55 am on April 10, 2009 Permalink | Reply

      Thansk you

c
compose new post
j
next post/next comment
k
previous post/previous comment
r
reply
e
edit
o
show/hide comments
t
go to top
l
go to login
h
show/hide help
esc
cancel