Last active
February 21, 2017 19:27
-
-
Save robbiegod/29e7336e9c7ef143d950d1a0980ebef5 to your computer and use it in GitHub Desktop.
makeImage with PHP function
This file contains hidden or 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 | |
function makeImage( $msg, $msg2, $font='./arial.ttf', $fontsize=40, $output='pic1.png') | |
{ | |
$fontcolor = imagecolorallocate($im, 128, 128, 128); | |
echo $msg; | |
echo "<br/>".$msg2; | |
$backgroundImg = imagecreatefromjpeg("logo-usarmy-with-texture-640x360.jpg"); | |
$cor = imagecolorallocate($backgroundImg, 0,0,0); | |
// imagestring($backgroundImg,5,126,22,"Dear Roy Nelsen", $cor); | |
// position msg | |
$tb = imagettfbbox($fontsize, 0, $font, $msg); | |
$x = ceil((640 - $tb[2]) / 2); | |
$y = ceil((360 - $tb[3]) / 2); | |
// POSITION msg2 | |
$tb2 = imagettfbbox($fontsize, 0, $font, $msg2); | |
$x2 = ceil((640 - $tb2[2]) / 2); | |
$y2 = ceil((360 - $tb2[3]) / 2 + 60); | |
imagettftext($backgroundImg, $fontsize, 0, $x, $y, $fontcolor, $font, $msg); | |
imagettftext($backgroundImg, $fontsize, 0, $x2, $y2, $fontcolor, $font, $msg2); | |
header('Content-type: image/png'); | |
imagepng($backgroundImg, "message1.png"); | |
imagedestroy($backgroundImg); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment