Skip to content

Instantly share code, notes, and snippets.

@robbiegod
Last active February 21, 2017 19:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robbiegod/29e7336e9c7ef143d950d1a0980ebef5 to your computer and use it in GitHub Desktop.
Save robbiegod/29e7336e9c7ef143d950d1a0980ebef5 to your computer and use it in GitHub Desktop.
makeImage with PHP function
<?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