Skip to content

Instantly share code, notes, and snippets.

@stefanocudini
Created March 24, 2012 23:45
Show Gist options
  • Save stefanocudini/2189163 to your computer and use it in GitHub Desktop.
Save stefanocudini/2189163 to your computer and use it in GitHub Desktop.
image text centered
<?
header('Content-Type: image/png');
$size= 80;
$extImg = imagecreatetruecolor($size,$size);
$targetFileImg = 'mime.png';
$ext = trim($_GET['t']);
$ctext = imagecolorallocate($extImg, 100, 100, 100); //testo
$ctrasp = imagecolorallocate($extImg, 200,200,200); //sfondo
imagefilledrectangle($extImg,0,0,$size,$size,$ctrasp);
$font = 5;#imageloadfont('trebuc.ttf');
$fontW = ImageFontWidth($font);
$fontH = ImageFontHeight($font);
$textW = $fontW * strlen($ext);
$textCenter = ceil(($size - $textW) / 2);
$textH = $fontH;
$textMiddle = ceil(($size - $textH) / 2);
imagestring($extImg, $font, $textCenter, $textMiddle, $ext, $ctext);
imagepng($extImg);//crea file thumb!
imagedestroy($extImg);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment