How to Generate a Personalized “I’m Attending” Event Banner Dynamically Using PHP and GD Library

PDF in WordPress using FPDF : Custom PDF Generator

Creating personalized event banners can help promote engagement on platforms like LinkedIn, Instagram, or Twitter.

Instead of manually editing each banner, you can automatically generate them using PHP and GD Library, allowing each attendee to download their custom “I’m Attending” banner instantly.

In this blog, we’ll walk through a real working PHP example that generates a banner using a base PNG template, adds the attendee’s profile photo, and overlays their name in a clean, centered layout.

 

Requirements

Before getting started, make sure you have:

  • PHP installed with GD library enabled (extension=gd in php.ini).
  • A base template image (e.g., attending-share20.png).
  • A TrueType font file (font.ttf) in the same directory.
  • A folder named generated/ with write permissions (chmod 777 generated/).

 

Complete PHP Code

    <?php
  $designation = "";
  $leadcode = $_POST['leadcode'];
  $email = $_POST['email'];
  $batch_id = $_POST['batch_id'];
  $stu_name = $_POST['stu_name'];
  $image = $_FILES['user_image']['tmp_name'];
  $imgp = $_POST['codeb'];

  // Load base banner image
  $base = imagecreatefrompng($imgp);

  // Font files
  $font_bold = "font.ttf";
  $font_regular = "font.ttf";

  if (!file_exists($font_bold) || !file_exists($font_regular)) {
    die("Font files missing!");
  }

  // Define colors
  $red = imagecolorallocate($base, 33, 114, 255);
  $black = imagecolorallocate($base, 0, 0, 0);
  $white = imagecolorallocate($base, 255, 255, 255);

  // Add user profile photo
  $userImg = imagecreatefromstring(file_get_contents($image));
  $userImg = imagescale($userImg, 210, 210);
  imagecopy($base, $userImg, 200, 255, 0, 0, 210, 210);

  // Center the student's name horizontally
  $name_box = imagettfbbox(16, 0, $font_bold, $stu_name);
  $text_width = $name_box[2] - $name_box[0];
  $image_width = imagesx($base);
  $x_center = ($image_width - $text_width) / 2;

  // Add student name text
  imagettftext($base, 16, 0, $x_center, 500, $white, $font_bold, $stu_name);

  // Save the generated image
  $fileName = "generated/" . $leadcode . ".png";
  imagepng($base, $fileName);

  // Clean up memory
  imagedestroy($base);
  imagedestroy($userImg);

  // Return file path
  $generatedImage = $fileName;
  echo "Banner created successfully: <a href='$generatedImage' target='_blank'>$generatedImage</a>";
?>


    

 

Code Explanation

Section Description
imagecreatefrompng() Loads the base template image (your event banner).
Font Validation Checks that required font files exist before adding text.
imagecolorallocate() Defines the RGB colors used for text or shapes.
imagecreatefromstring() Converts uploaded profile photo into an image resource.
imagescale() Resizes the uploaded image to fit your banner dimensions.
imagecopy() Merges the profile picture onto the base image at a defined position.
imagettftext() Adds the student’s name text centered on the banner using TrueType fonts.
imagepng() Saves the generated image file to the “generated” directory.

 

Sample Output

    +------------------------------------------------+
|    [ Event Banner Background Image ]           |
|                                                |
|         [User’s Profile Image]                 |
|                                                |
|                 John Doe                       |
+------------------------------------------------+


    

Result file:
📁 /generated/LEAD123.png

 

How to Use in Your Website

You can create a small form like this:

    
<form method="POST" enctype="multipart/form-data" action="generate_banner.php">
  <input type="text" name="stu_name" placeholder="Enter your name" required><br>
  <input type="file" name="user_image" accept="image/*" required><br>
  <input type="hidden" name="leadcode" value="LEAD123">
  <input type="hidden" name="codeb" value="attending-share20.png">
  <button type="submit">Generate My Banner</button>
</form>

    

Real-World Use Cases

  • 🎓 Education: “I’m Attending” banners for webinars or workshops.
  • 🧑‍💼 Corporate: Event attendee badges.
  • 🎉 Marketing: Personalized shareable posters for participants.
  • 🏆 Competitions: Auto-generated certificates or announcement images.

 

Conclusion

With just a few lines of PHP using the GD library, you can automate the creation of professional, personalized event banners.

It’s a great way to encourage attendees to share their participation and boost event visibility on social media.

 

Previous Article

SQL Injection Attack Notifier (ready-to-deploy MU-plugin)

Next Article

Understanding Cross-Origin Resource Sharing (CORS) in PHP: How to Set HTTP Headers

Write a Comment

Leave a Comment

Your email address will not be published. Required fields are marked *

Subscribe to our Newsletter

Subscribe to our email newsletter to get the latest posts delivered right to your email.
Pure inspiration, zero spam ✨