N1kol4N1k Posted February 27, 2013 Share Posted February 27, 2013 Hi guys, i have problem with php. I want to make website which create baner for user when they fill out the form. This is banner (without text and image): http://misterijeforum.com/nik/images/medium.png I made form also: http://misterijeforum.com/nik/small.html But i got problems with php script. I'm not php programmer, but i created "something" <?php header('Content-Type: image/png'); $im = ImageCreateFromPng("images/medium.png"); $black = imagecolorallocate($im, 0, 0, 0); $ime = "$fullname"; $interests = "%interests"; $school = "%school"; $fb = "%facebook"; $msn = "%msn"; $mail = "%mail"; $start_x = 1; $start_y = 1; Imagettftext($im, 12, 0, $start_x, $start_y, $black, 'verdana.ttf', $ime); Imagepng($im); ImageDestroy($im); ?> I made just for full name, but i don't know how to storage that new image in folder "images" and show image to user. And is this code good ? Quote Link to comment Share on other sites More sharing options...
N1kol4N1k Posted February 27, 2013 Author Share Posted February 27, 2013 (edited) I know that code is bad I just found it on internet and modified it. Can you explain me how to do that or better to give me code. So i want to, when user fill out the form and click on "submit", it generate benner with informations which user write in form and that picture/banner storage in folder "images". Backgroud of banner will be www.misterijeforum.com/nik/images/medium.png . Thank you so much Edited February 27, 2013 by N1kol4N1k Quote Link to comment Share on other sites More sharing options...
Psycho Posted February 28, 2013 Share Posted February 28, 2013 This forum (PHP Coding Help) is for people to get help with code they have written. There is a separate forum here for Freelancing if you want someone to write the code for you. Quote Link to comment Share on other sites More sharing options...
Psycho Posted February 28, 2013 Share Posted February 28, 2013 (edited) OK, I was in a good mood. A quick google search directed me to a tutorial on this very site (http://www.phpfreaks.com/tutorial/php-add-text-to-image) which I used to create the following: <?php error_reporting(E_ALL); //Set values based upon form POST data $fullname = "Ricardo Montobaln"; $location = "Denver, Colorado"; $school = "School of Hard Knocks"; $facebook = "www.facebook.com/myprofile"; $email = "myname@domain.com"; //Path to image $imageName = 'images/medium.png'; //Font face and size $font = 'verdana.ttf'; $fontSize = 10; $spacing = 22; //horizontal spacing between lines //Create image object $image = ImageCreateFromPng($imageName ); //Pick color for the text $fontColor = imagecolorallocate($image, 255, 255, 255); //Set start x & y positions $x = 75; $y = 16; //Add name text imagettftext($image, $fontSize, 0, $x, $y, $fontColor, $font, $fullname); //Move y position down and add location text imagettftext($image, $fontSize, 0, $x, $y+=$spacing, $fontColor, $font, $location); //Move y position down and add school text imagettftext($image, $fontSize, 0, $x, $y+=$spacing, $fontColor, $font, $school); //Move y position down and add facebook text imagettftext($image, $fontSize, 0, $x, $y+=$spacing, $fontColor, $font, $facebook); //Move y position down and add email text imagettftext($image, $fontSize, 0, $x, $y+=$spacing, $fontColor, $font, $email); header('Content-Type: image/png'); //Output image to the browser imagepng($image); //Delete the image resource imagedestroy($image); ?> Note: You set the position of the first line using the values for $x and $y. Then the $spacing variable is used to move down to the next line after you place a line of text. That is done by using "$y+=$spacing" inside the function call for imagettftext(). That will increment $y by the value of $spacing. EDIT: you may want to think abut reducing the font size. Otherwise values that are a little long will go past the right edge of the black area. Or you could make the image wider. Edited February 28, 2013 by Psycho Quote Link to comment Share on other sites More sharing options...
N1kol4N1k Posted March 4, 2013 Author Share Posted March 4, 2013 It's working, thank you so much. It's work perfectly on localhost, but online is problem with font: "Could not find/open font" Quote Link to comment Share on other sites More sharing options...
Psycho Posted March 4, 2013 Share Posted March 4, 2013 You should pick a font that will be available on your server, such as Arial. If you are developing on a Windows machine and your app is running on a Linux box you will be limited on the fonts available. Quote Link to comment Share on other sites More sharing options...
Barand Posted March 4, 2013 Share Posted March 4, 2013 You also need to make sure the $font variable contains the correct path to the font file Quote Link to comment Share on other sites More sharing options...
N1kol4N1k Posted March 11, 2013 Author Share Posted March 11, 2013 (edited) EDIT~ Fixed ... Edited March 11, 2013 by N1kol4N1k 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.