CocaCola Posted May 5, 2013 Share Posted May 5, 2013 (edited) Struggling to change font & font size. This is the code i'm using, and it works perfectly fine apart from i need to change the outputted font's but as it's joined to a image i can't do that with css after the image so need to do it before its processed but have no clue how? Please any help is appreciated. <?php // load the image from the file specified: $im = imagecreatefrompng("image.png"); // if there's an error, stop processing the page: if(!$im) { die(""); } // define some colours to use with the image $black = imagecolorallocate($im, 80, 77, 77); // get the width and the height of the image $width = imagesx($im); $height = imagesy($im); $textt = $_GET['textt']; $dealer = $_GET['dealer']; $purchase = $_GET['purchase']; $name = $_GET['name']; $address = $_GET['address']; $address1 = $_GET['address1']; // store the text we're going to write in $textt // calculate the left position of the text: $leftTextPos = ( $width - imagefontwidth($font)*strlen($textt) )/2; $leftTextPos = ( $width - imagefontwidth($font)*strlen($dealer) )/2; // finally, write the string: imagestring($im,$font,$leftTextPos-210,$height-295,$textt,$black); imagestring($im,$font,$leftTextPos-210,$height-165,$dealer,$black); imagestring($im,$font,$leftTextPos-200,$height-115,$purchase,$black); imagestring($im,$font,$leftTextPos-130,$height-70,$name,$black); imagestring($im,$font,$leftTextPos-100,$height-50,$address,$black); imagestring($im,$font,$leftTextPos-00,$height-50,$address1,$black); // output the image // tell the browser what we're sending it Header('Content-type: image/png'); // output the image as a png imagepng($im); // tidy up imagedestroy($im); ?> Edited May 5, 2013 by CocaCola Quote Link to comment Share on other sites More sharing options...
Q695 Posted May 5, 2013 Share Posted May 5, 2013 You don't change PHP font as PHP is server side, you change CSS/HTML font. If this is a captcha, you want to do it with a font included somewhere on your website. Quote Link to comment Share on other sites More sharing options...
CocaCola Posted May 5, 2013 Author Share Posted May 5, 2013 Hi Q695, My script does the following : User inputs 5 details into text fields then hit's submit. This creates a image that's uneditable after it has been submitted. So i require to be able to change the font within the script itself before it being submitted. Hopefully this makes sense. Quote Link to comment Share on other sites More sharing options...
PaulRyan Posted May 5, 2013 Share Posted May 5, 2013 imagettftext Quote Link to comment Share on other sites More sharing options...
CocaCola Posted May 5, 2013 Author Share Posted May 5, 2013 imagettftext Hi PaulRyan, Thanks i've been looking into imagegettext, but i'm really not sure how to convert what i have to this. Quote Link to comment Share on other sites More sharing options...
Barand Posted May 5, 2013 Share Posted May 5, 2013 imagestring uses a set of built-in, fixed size monospaced font numbered 1 to 5. If you use imagettftext instead you can use any ttf font on the server and any size. Calculating the text size is a little more difficult as you have to call imagettfbbox which returns the corner coords of a box that contains the text Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.