gfX Posted May 15, 2011 Share Posted May 15, 2011 Hi guys, Here is what I have so far: http://www.autoshopgarage.com/new-era/generate.php What I am trying to do is instead of having Line 1 and Line 2, I want to just have one big textarea so I don't have to limit the user so much. I did it this way because I want to have two versions of text, the light version and the bold version. Is it possible to have two different fonts with just one textarea of text? Right now I have two functions: ImageTTFText($image, $fontSize, $fontRotation, 435, 80, $color, $font1, wordwrap($first, 18, "\n", true)); ImageTTFText($image, $fontSize, $fontRotation, 485,120, $color_black, $font2, wordwrap($last, 18, "\n", true)); So I would limit that to just 1, and it would automatically wordwrap but what would I put for the $font variable? Is this even possible? I was thinking of just using BBCode so they could type in [b*]Bold Text[/b*] and it would use the Bold version of the font if it sees that. Any help is appreciated. Thanks! Here is the full code: <?php $first = $_GET['first']; $last = $_GET['last']; $font_color = $_GET['color']; header("Content-type: image/png"); $image = imagecreatefrompng ( "banner_blank.png" ); $color_black = imagecolorallocate($image, 0, 0, 0); $color_red = imagecolorallocate($image, 255, 0, 0); if($font_color == "Red") { $color = $color_red; } elseif($font_color == "Black") { $color = $color_black; } $font1 = 'HelveticaNeueLTStd-BdEx.ttf'; $font2 = 'HelveticaNeueLTStd-LtEx.ttf'; $fontSize = "21"; ImageTTFText($image, $fontSize, $fontRotation, 435, 80, $color, $font1, wordwrap($first, 18, "\n", true)); ImageTTFText($image, $fontSize, $fontRotation, 485,120, $color_black, $font2, wordwrap($last, 18, "\n", true)); imagepng ( $image ); imagedestroy ( $image ); ?> Link to comment https://forums.phpfreaks.com/topic/236469-php-create-image-with-dynamic-text-fonts-question/ Share on other sites More sharing options...
gfX Posted May 15, 2011 Author Share Posted May 15, 2011 OK I am getting close! After reading on Stackoverflow here is what I have now: http://www.autoshopgarage.com/new-era/test2.php?text=testing+%3Cb%3Escript%3C/b%3E%20this%20is%20so%20cool%20i%20love%20it That does what I want, the only problem with this is now I can't get the wordwrap to work! It should wrap to the next line, but I cannot seem to get it. Here is the new PHP code: <?php header('Content-type: image/png'); $im = imagecreatefrompng ( "banner_blank.png" ); $color = imagecolorallocate($image, 0, 0, 0); $tmp = $_GET['text']; $words = explode(" ", $tmp); $x = array(0,0,230); // DUMMY ARRAY WITH X POSITION FOR FIRST WORD $addSpace = 0; foreach($words as $word) { if($addSpace) $word = " ".$word; // IF WORD IS NOT THE FIRST ONE, THEN ADD SPACE if(stristr($word, "<b>")) { $font = 'HelveticaNeueLTStd-BdEx.ttf'; // BOLD FONT $replace = str_replace(array("<b>","</b>"), "", $word); $x = imagettftext($im, 20, 0, $x[2], 20, $color, $font, $replace); } else { $font = 'HelveticaNeueLTStd-LtEx.ttf'; // NORMAL FONT $x = imagettftext($im, 20, 0, $x[2], 20, $color, $font, $word); } $addSpace = 1; } imagepng($im); imagedestroy($im); ?> Anyone have any ideas? Thanks! Link to comment https://forums.phpfreaks.com/topic/236469-php-create-image-with-dynamic-text-fonts-question/#findComment-1215807 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.