Created
November 25, 2014 21:49
-
-
Save joeydsmith/49e734f3d766cd3869ef to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
Header ("Content-type: image/jpeg"); | |
function ImageTTFCenter($image, $text, $font, $size, $angle = 45) { | |
$xi = imagesx($image); | |
$yi = imagesy($image); | |
$box = imagettfbbox($size, $angle, $font, $text); | |
$xr = abs(max($box[2], $box[4])); | |
$yr = abs(max($box[5], $box[7])); | |
$x = intval(($xi - $xr) / 2); | |
$y = intval(($yi + $yr) / 2); | |
return array($x, $y); | |
} | |
$im = @imagecreatefrompng('someimage.png'); | |
// Create some colors | |
$white = imagecolorallocate($im, 255, 255, 255); | |
$grey = imagecolorallocate($im, 128, 128, 128); | |
$black = imagecolorallocate($im, 0, 0, 0); | |
//imagefilledrectangle($im, 0, 0, 399, 29, $white); | |
// The text to draw | |
$text = $_GET["text"]; | |
$uploads_dir = '/'; | |
// Replace path by your own font path | |
$font = 'ITCKRIST.TTF'; | |
//image file name | |
//$name ="$fbid.png"; | |
$name = $uploads_dir."test.png"; //this saves the image inside uploaded_files folder | |
list($x, $y) = ImageTTFCenter($im, $text, $font, 20); | |
// Add some shadow to the4 text | |
imagettftext($im, 20, 0, $x, $y+1, $grey, $font, $text); | |
// Add the text | |
imagettftext($im, 20, 0, $x, $y, $black, $font, $text); | |
// Using imagepng() results in clearer text compared with imagejpeg() | |
//imagepng($im); | |
ImageJPEG($im,null,100); | |
imagedestroy($im); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment