Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function imagettfstroketext(&$image, $size, $angle, $x, $y, &$textcolor, &$strokecolor, $fontfile, $text, $px) {
- for($c1 = ($x-abs($px)); $c1 <= ($x+abs($px)); $c1++)
- for($c2 = ($y-abs($px)); $c2 <= ($y+abs($px)); $c2++)
- $bg = imagettftext($image, $size, $angle, $c1, $c2, $strokecolor, $fontfile, $text);
- return imagettftext($image, $size, $angle, $x, $y, $textcolor, $fontfile, $text);
- }
- //Process all the GET arguments
- //text
- if(!isset($_GET["text"]))
- die;
- $text = $_GET["text"];
- if(strlen($text) <= 0)
- die;
- $text = strtoupper($text);
- //opacity
- /*if(!isset($_GET["opacity"]))
- $opacity = 256;
- else
- $opacity = $_GET["opacity"];
- if(is_null($opacity) || $opacity > 256)
- $opacity = 256;
- elseif($opacity < 0)
- $opacity=0;*/
- //Font size
- if(!isset($_GET["fontSize"]))
- $fontSize = 50;
- else
- $fontSize = $_GET["fontSize"];
- if(is_null($fontSize))
- $fontSize = 64;
- elseif($fontSize > 128)
- $fontSize = 128;
- elseif($fontSize < 16)
- $fontSize = 16;
- $strokeSize = round($fontSize * 0.05);
- //Determine how much we need to offset the font
- $totalCharHeight = $fontSize + (2 * $strokeSize);
- $sizeOffset = $totalCharHeight * 0.2;
- //Figure out how big of an image we need
- $box = imagettfbbox($fontSize,0,"fonts/impact.ttf",$text);
- $width = abs($box[4] - $box[0]);
- $width = $width + (2 * $sizeOffset);
- $height = abs($box[5] - $box[1]);
- $height = $height + (2 * $sizeOffset);
- //Create the image
- $img = imagecreatetruecolor($width,$height);
- //Allocate colors
- $bg = imagecolorallocate($img,0,61,166);
- //$fontColor = imagecolorallocatealpha($img,0,0,0,$opacity);
- //$strokeColor = imagecolorallocatealpha($img,201,215,238,$opacity);
- $fontColor = imagecolorallocate($img,0,0,0);
- $strokeColor = imagecolorallocate($img,201,215,238);
- imagefill($img,0,0,$bg);
- //Place the text
- imagettfstroketext($img,$fontSize,0,$sizeOffset,$fontSize+$sizeOffset+$strokeSize,$fontColor,$strokeColor,"fonts/impact.ttf",$text,$strokeSize);
- //Send the image
- header('Content-type: image/png');
- imagepng($img);
- imagedestroy($img);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment