Check out "Do you speak JavaScript?" - my latest video course on advanced JavaScript.
Language APIs, Popular Concepts, Design Patterns, Advanced Techniques In the Browser

PHP: add text to transparent PNG image

Simple way to produce numbered image with PHP. The script uses PHP GD.

$originalImage = "group_icon.png";
  if (file_exists($originalImage)) {
    $im = imagecreatefrompng($originalImage);
    imagesavealpha($im, true);
    // important to keep the png's transparency 	
    if (!$im) {
      die("im is null");
    }
    $black = imagecolorallocate($im, 0, 0, 0);
    $width = 36;
    // the width of the image	
    $height = 36;
    // the height of the image	
    $font = 2;
    // font size
    $digit = $i;
    // digit
    $leftTextPos = 19 - (strlen($digit) * 3);
    $outputImage = "group_icon_".$digit.
    ".png";
    imagestring($im, $font, $leftTextPos, 9, $digit, $black);
    imagepng($im, $outputImage, 0);
    imagedestroy($im);
  }
If you enjoy this post, share it on Twitter, Facebook or LinkedIn.