Guest User

Untitled

a guest
Nov 24th, 2014
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.08 KB | None | 0 0
  1. <?php
  2.  
  3. function imagettfstroketext(&$image, $size, $angle, $x, $y, &$textcolor, &$strokecolor, $fontfile, $text, $px) {
  4.  
  5.     for($c1 = ($x-abs($px)); $c1 <= ($x+abs($px)); $c1++)
  6.         for($c2 = ($y-abs($px)); $c2 <= ($y+abs($px)); $c2++)
  7.             $bg = imagettftext($image, $size, $angle, $c1, $c2, $strokecolor, $fontfile, $text);
  8.  
  9.    return imagettftext($image, $size, $angle, $x, $y, $textcolor, $fontfile, $text);
  10. }
  11.  
  12. //Process all the GET arguments
  13. //text
  14. if(!isset($_GET["text"]))
  15.     die;
  16.    
  17. $text = $_GET["text"];
  18. if(strlen($text) <= 0)
  19.     die;
  20.    
  21. $text = strtoupper($text);
  22.  
  23. //opacity
  24. /*if(!isset($_GET["opacity"]))
  25.     $opacity = 256;
  26. else
  27.     $opacity = $_GET["opacity"];
  28.    
  29. if(is_null($opacity) || $opacity > 256)
  30.     $opacity = 256;
  31. elseif($opacity < 0)
  32.     $opacity=0;*/
  33.    
  34. //Font size
  35. if(!isset($_GET["fontSize"]))
  36.     $fontSize = 50;
  37. else
  38.     $fontSize = $_GET["fontSize"];
  39.    
  40. if(is_null($fontSize))
  41.     $fontSize = 64;
  42. elseif($fontSize > 128)
  43.     $fontSize = 128;
  44. elseif($fontSize < 16)
  45.     $fontSize = 16;
  46.  
  47. $strokeSize = round($fontSize * 0.05); 
  48.  
  49. //Determine how much we need to offset the font
  50. $totalCharHeight = $fontSize + (2 * $strokeSize);
  51. $sizeOffset = $totalCharHeight * 0.2;
  52.    
  53. //Figure out how big of an image we need
  54. $box = imagettfbbox($fontSize,0,"fonts/impact.ttf",$text);
  55. $width = abs($box[4] - $box[0]);
  56. $width = $width + (2 * $sizeOffset);
  57. $height = abs($box[5] - $box[1]);
  58. $height = $height + (2 * $sizeOffset);
  59.  
  60. //Create the image
  61. $img = imagecreatetruecolor($width,$height);
  62.  
  63. //Allocate colors
  64. $bg = imagecolorallocate($img,0,61,166);
  65. //$fontColor = imagecolorallocatealpha($img,0,0,0,$opacity);
  66. //$strokeColor = imagecolorallocatealpha($img,201,215,238,$opacity);
  67. $fontColor = imagecolorallocate($img,0,0,0);
  68. $strokeColor = imagecolorallocate($img,201,215,238);
  69.  
  70. imagefill($img,0,0,$bg);
  71.  
  72. //Place the text
  73. imagettfstroketext($img,$fontSize,0,$sizeOffset,$fontSize+$sizeOffset+$strokeSize,$fontColor,$strokeColor,"fonts/impact.ttf",$text,$strokeSize);
  74.  
  75. //Send the image
  76. header('Content-type: image/png');
  77. imagepng($img);
  78. imagedestroy($img);
  79. ?>
Advertisement
Add Comment
Please, Sign In to add comment