Created
November 25, 2014 21:37
-
-
Save joeydsmith/f5ae842e4d7b2a3788d0 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 | |
// Print two names on the picture, which accepted by query string parameters. | |
$n1 = $_GET['n1']; | |
$n2 = $_GET['n2']; | |
Header ("Content-type: image/jpeg"); | |
$image = imageCreateFromPNG("someimage.png"); | |
$color = ImageColorAllocate($image, 255, 255, 255); | |
// Calculate horizontal alignment for the names. | |
$BoundingBox1 = imagettfbbox(13, 0, 'ITCKRIST.TTF', $n1); | |
$boyX = ceil((125 - $BoundingBox1[2]) / 2); // lower left X coordinate for text | |
$BoundingBox2 = imagettfbbox(13, 0, 'ITCKRIST.TTF', $n2); | |
$girlX = ceil((107 - $BoundingBox2[2]) / 2); // lower left X coordinate for text | |
// Write names. | |
imagettftext($image, 23, 0, $boyX+500, 100, $color, 'ITCKRIST.TTF', $n1); | |
imagettftext($image, 23, 0, $girlX+310, 92, $color, 'ITCKRIST.TTF', $n2); | |
// Return output. | |
ImageJPEG($image, NULL, 93); | |
ImageDestroy($image); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment