Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.
$name = $_REQUEST["name"]; $filename = "certificate.png"; //name of image file $fontsize = 30; //size of font $fontfile = "Arial"; //name of ttf file, w/o ttf extension (courier in this case) $text = "Congratulations ".$name.""; //text to write centered $text2 = "You will receive $1000"; //second line to write centered $im = imagecreatefrompng ($filename); //create the image resource list ($im_width, $im_height) = getimagesize($filename); //calculate the size of the bounding box $bbox = imagettfbbox($fontsize, 0, $fontfile, $text); $bbox2 = imagettfbbox($fontsize, 0, $fontfile, $text2); $text_width = $bbox-$bbox; $text_height = $bbox-$bbox; $text_width2 = $bbox2-$bbox2; $text_height2 = $bbox2-$bbox2; //write the text to the file, centered as calculated from (W-w)/2 //where W is the image dimension and w is the text dimension imagettftext($im, 30, 0, ($im_width-$text_width)/2, ($im_height-$text_height)/2, 0, $fontfile, $text); imagettftext($im, 20, 0, ($im_width-$text_width2)/2, ($im_height-$text_height2)/2 + 40, 0, $fontfile, $text2); header('Content-type: image/png'); imagepng($im); //destroy the image resource imagedestroy($im);
Add your voice to the tech community where 5M+ people just like you are talking about what matters.
Join the community of 500,000 technology professionals and ask your questions.