Sephiroth666 Posted October 6, 2009 Share Posted October 6, 2009 Hi there. I'm new here and I have a problem I can't solve on my own so I was hoping to get some help here. I tried to google my problem but I couldn't find anything. Here's my problem: I'm writing an event-site for my company. The admin is able to add new events to the site and can choose if he wants to upload a specific picture for this event or not. If the admin doesn't want to upload a picture I want to create an automatic picture in which the event-name is in with the GD-Libraries. I managed to create a new .php file that contains to script for the picture via php. Everything works except that there is no text on the picture and I can't figure out why. Here's the script that writes the GD-Libraries script in the new .php file. I hope you can help me. $neuesbild = "eventbilder/".$name.".php"; $open = fopen($neuesbild, 'w') or DIE("Kann Datei nicht öffnen<meta http-equiv=refresh content='2; URL=neuer_event.php?pid=09'>"); $var1 = "\$bild"; $var2 = "\$bg"; $var3 = "\$black"; $var4 = "\$text"; $var5 = "\$font"; $string = "<?php\n header('content-type: image/png');\n $var1 = imagecreate(320,150);\n $var2 = imagecolorallocate(\$bild, 255, 255, 255);\n $var3 = imagecolorallocate(\$bild, 0, 0, 0);\n $var4 = \"$name\";\n $var5 = \"times.ttf\";\n imagettftext(\$bild, 20, 0, 135, 80, \$black, \$font, \$text);\n imagepng(\$bild);\n ?>"; fwrite($open, $string); fclose($open); $bild = $name.".php"; Thank you very much Quote Link to comment https://forums.phpfreaks.com/topic/176656-gd-libraries-imagettftext/ Share on other sites More sharing options...
Daniel0 Posted October 6, 2009 Share Posted October 6, 2009 Why are you writing a file like that for all of them? Why not do like this instead? if ($hasPicture) { // output it, or show an <img> to it } else { // generate one } Quote Link to comment https://forums.phpfreaks.com/topic/176656-gd-libraries-imagettftext/#findComment-931333 Share on other sites More sharing options...
kickstart Posted October 6, 2009 Share Posted October 6, 2009 Hi I agree with the above. However looking at your code I suspect one issue is the line:- imagettftext(\$bild, 20, 0, 135, 80, \$black, \$font, \$text);\n which is missing a few quotes:- imagettftext(\$bild, 20, 0, 135, 80, \$black, '\$font', '\$text');\n Not sure what can do with $bild and $black, as they should be references (to an image and to a colour for that image respectively) and I would expect the variables are referring to things in the main script which will no longer exist (and even if they did exist they couldn't be accessed by the generated script) when the generated script is run. All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/176656-gd-libraries-imagettftext/#findComment-931359 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.