bullbreed Posted March 16, 2010 Share Posted March 16, 2010 I am trying to create an image using PHP and GD library. What I want to do is; 1. User inputs required text 2. User selects a font from list 3. PHP and GD creates the image then saves it to the database in uploads folder 4. The generated image appears on screen after being called from the database The following code I did does most of this but the user form for this is on a page called productdisplay.php and the php script is on create text.php so when the image is created it doesn't yet save it but displays it on screen on create-text.php When the user runs the script I want to stay in the productdisplay.php page, save the image to the server then call it to the page. Heres my code <?php //Report any errors ini_set("display_errors", "1"); error_reporting(E_ALL); // Create a 165x45 image $im = imagecreatetruecolor(165, 45); $white = imagecolorallocate($im, 0xFF, 0xFF, 0xFF); $black = imagecolorallocate($im, 0x00, 0x00, 0x00); // Get the Text String from the Text Field $string = $_POST['input']; // Get the Font Type from the Menu Field $font = $_POST['fontselect']; //Set the Path to the Font Directory $font_file = 'fonts/'; // Make the background black imagefilledrectangle($im, 0, 0, 164, 44, $black); // Draw the Text from Text String using font size 14 imagefttext($im, 14, 0, 30, 30, $white, $font, $string); // Output the image to the browser header('Content-Type: image/png'); imagepng($im); // Clear the image from memory imagedestroy($im); ?> What do I change to save the image, display on screen and stay on same page? Thanks B Quote Link to comment https://forums.phpfreaks.com/topic/195477-php-gd-issue/ Share on other sites More sharing options...
bullbreed Posted March 16, 2010 Author Share Posted March 16, 2010 is it somethiing to do with the imagepng($im); Quote Link to comment https://forums.phpfreaks.com/topic/195477-php-gd-issue/#findComment-1027321 Share on other sites More sharing options...
nafetski Posted March 16, 2010 Share Posted March 16, 2010 You would want to save the image (a second parameter in imgpng), then either redirect to it, or underneath it put it's source in an <img> tag. Should do the trick Quote Link to comment https://forums.phpfreaks.com/topic/195477-php-gd-issue/#findComment-1027323 Share on other sites More sharing options...
bullbreed Posted March 17, 2010 Author Share Posted March 17, 2010 Thanks for that. I did a little tinkering around and got it working but I have a few questions that probably need an advanced user. First of all here is the code <?php ini_set("display_errors", "1"); error_reporting(E_ALL); //Report any errors // Create a 165x45 image $im = imagecreatetruecolor(165, 45); $white = imagecolorallocate($im, 0xFF, 0xFF, 0xFF); $black = imagecolorallocate($im, 0x00, 0x00, 0x00); // Get the Text String from the Text Field $string = $_POST['input']; // Get the Font Type from the Menu Field $font = $_POST['fontselect']; //Set the Path to the Font Directory $font_file = 'fonts/'; //Set the Path to the uploads folder $location = 'uploads/test.png'; // Make the background black imagefilledrectangle($im, 0, 0, 164, 44, $black); // Draw the Text from Text String using font size 14 imagefttext($im, 14, 0, 30, 30, $white, $font, $string); // Output the image to the browser header('Content-Type: image/png'); //Save the image to the uploads folder imagepng($im,$location); // Clear the image from memory imagedestroy($im); ?> Question 1 I get a few notices and errors as below. How do I sort these Warning: imagefttext() [function.imagefttext]: Could not find/open font in C:\xampp\htdocs\site\includes\prodtype.php on line 27 Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\site\productdesign.php:11) in C:\xampp\htdocs\site\includes\prodtype.php on line 30 Question 2 I store the image that is created as 'test.png' in the 'uploads' folder but I tink I need to store it as something else because if 2 people are using the site at once the image will change to the latest users text so how would I store it related to the session? And would a user have to be logged in to start the session? Quote Link to comment https://forums.phpfreaks.com/topic/195477-php-gd-issue/#findComment-1027552 Share on other sites More sharing options...
bullbreed Posted March 17, 2010 Author Share Posted March 17, 2010 I know some of the errors are due to the form not being completed so could I run the script from another page without the browser going to that page? Quote Link to comment https://forums.phpfreaks.com/topic/195477-php-gd-issue/#findComment-1027596 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.