cwncool Posted June 16, 2006 Share Posted June 16, 2006 I'm trying to make a script to create a new image from "http://www.gigacat.com/kitten.jpeg" (that's my own server) into another image with a string in the textbox of the picture. These are the two codes i've tried.[code]<?php$id = imagecreatefromjpeg("kitten.jpeg");$string = "Meow, meow, meow!";$black = imagecolorallocate($id, 0, 0, 0);imagestring($id, "font.ttf", 170, 117, $string, $black);imagejpeg($id,"newkitten.jpeg");?>[/code]on this first one i just end up with a blank, white page.and this.[code]<?phpheader("Content-type: image/jpeg");$id = imagecreatefromjpeg("kitten.jpeg");$string = "Meow, meow, meow!";$black = imagecolorallocate($id, 0, 0, 0);imagestring($id, "font.ttf", 170, 117, $string, $black);imagejpeg($id,"newkitten.jpeg");?>[/code]on this one, all I did was add the header, and it creates another blank, white page displaying the script's url on the page. Can someone please help me figure out what's wrong? Thanx! Quote Link to comment https://forums.phpfreaks.com/topic/12210-gd-dynamic-image-help/ Share on other sites More sharing options...
poirot Posted June 17, 2006 Share Posted June 17, 2006 Try to change:[code]imagejpeg($id,"newkitten.jpeg");[/code]To [code]imagejpeg($id);[/code]Now, you can't use a ttf font with imagestring, you must use imagettftext():[a href=\"http://www.php.net/imagettftext\" target=\"_blank\"]http://www.php.net/imagettftext[/a] Quote Link to comment https://forums.phpfreaks.com/topic/12210-gd-dynamic-image-help/#findComment-46538 Share on other sites More sharing options...
cwncool Posted June 17, 2006 Author Share Posted June 17, 2006 i got it working (thanx), but is there a way to make the font size smaller? Thanx! Quote Link to comment https://forums.phpfreaks.com/topic/12210-gd-dynamic-image-help/#findComment-46543 Share on other sites More sharing options...
poirot Posted June 17, 2006 Share Posted June 17, 2006 [!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]imagettftext ( resource image, [b]float size[/b], float angle, int x, int y, int color, string fontfile, string text )[/quote][a href=\"http://www.php.net/imagettftext\" target=\"_blank\"]http://www.php.net/imagettftext[/a] Quote Link to comment https://forums.phpfreaks.com/topic/12210-gd-dynamic-image-help/#findComment-46545 Share on other sites More sharing options...
cwncool Posted June 17, 2006 Author Share Posted June 17, 2006 thanx. i tried that, but must have done something wrong! :) thanx for your help! Quote Link to comment https://forums.phpfreaks.com/topic/12210-gd-dynamic-image-help/#findComment-46550 Share on other sites More sharing options...
cwncool Posted June 17, 2006 Author Share Posted June 17, 2006 Okay. The script I have working now is....[code]<?phpheader("Content-type: image/jpeg");$id = imagecreatefromjpeg("kitten.jpeg");$string = $_GET['text'];$black = imagecolorallocate($id, 0, 0, 0);imagettftext ($id, 7, 0, 160, 120, $black, "font.ttf", $string);imagejpeg($id);?>[/code]Instead of taking me to a page with the PHP image on it, how can I make it save it as an image on my server and then forward to another page, html, that says "the cat says.." and then shows the image on it or to just refresh the page with instead of the example image, but the generated image. Like [a href=\"http://atom.smasher.org/chinese/\" target=\"_blank\"]here[/a] Thanx! Quote Link to comment https://forums.phpfreaks.com/topic/12210-gd-dynamic-image-help/#findComment-46781 Share on other sites More sharing options...
cwncool Posted June 18, 2006 Author Share Posted June 18, 2006 anybody? Quote Link to comment https://forums.phpfreaks.com/topic/12210-gd-dynamic-image-help/#findComment-47019 Share on other sites More sharing options...
.josh Posted June 18, 2006 Share Posted June 18, 2006 you should be able to call that script as the source in your image tag. for example, if that script was called blah.php you should be able to do like<img src = 'blah.php' /> Quote Link to comment https://forums.phpfreaks.com/topic/12210-gd-dynamic-image-help/#findComment-47021 Share on other sites More sharing options...
deadonarrival Posted June 18, 2006 Share Posted June 18, 2006 <img src="page.php" />should just work. page.php being this script. Quote Link to comment https://forums.phpfreaks.com/topic/12210-gd-dynamic-image-help/#findComment-47023 Share on other sites More sharing options...
cwncool Posted June 18, 2006 Author Share Posted June 18, 2006 i know that and that's what I have, but after submit on the page (http://www.gigacat.com/kitten.html (it will be php once i figure this out)) it takes me to the image file because the script has the image header and creates the image file. i want it to refresh the page with instead of blank php image file, with the one with the text so the form is still there... You see? Quote Link to comment https://forums.phpfreaks.com/topic/12210-gd-dynamic-image-help/#findComment-47034 Share on other sites More sharing options...
.josh Posted June 18, 2006 Share Posted June 18, 2006 are you sure you don't have the image file as the action='..' in your form? Quote Link to comment https://forums.phpfreaks.com/topic/12210-gd-dynamic-image-help/#findComment-47036 Share on other sites More sharing options...
cwncool Posted June 18, 2006 Author Share Posted June 18, 2006 the image file is the action in my form, but when i put the form page as the action in the form it doesn't work. when the form is like this...[code]<img src="kitten1.php?text=<?php echo $string ?>"><form action="kitten.php" method="GET"><p>What do you want the kitten to say? <input type="text" name="text" maxlength="19" /></p><p><input type="submit" value="Talk, Kitty!"></p></form>[/code]it just refreshes the page with the text entered in the top url of the form page, but does nothing to the image.... Quote Link to comment https://forums.phpfreaks.com/topic/12210-gd-dynamic-image-help/#findComment-47150 Share on other sites More sharing options...
.josh Posted June 19, 2006 Share Posted June 19, 2006 i don't think you can combine the two scripts. the idea of using the script as a source is that you are creating a virtual link, and i don't think you can create a virtual link from one place to itself like that. you are going to have to seperate the image generation script from the form script. make your form script display the image, with the kitten.php as the source, and the form itself. then do the action to itself. example:kitten.php[code]<?phpif ($_GET['text']) { $text = $_GET['text'];} else { $text = 'meow';}//build your image using $text//and end it with the header?>[/code]form.php[code]<img src="kitten1.php?text=<?= $_GET['text'] ?>"><form action="<?= $_SERVER['PHP_SELF']" ?> method="GET"><p>What do you want the kitten to say? <input type="text" name="text" maxlength="19" /></p><p><input type="submit" value="Talk, Kitty!"></p></form>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/12210-gd-dynamic-image-help/#findComment-47200 Share on other sites More sharing options...
cwncool Posted June 19, 2006 Author Share Posted June 19, 2006 that worked perfectly! :) :) Thanx Crayon![a href=\"http://www.gigacat.com/kitten.php\" target=\"_blank\"]here's the working script![/a] Quote Link to comment https://forums.phpfreaks.com/topic/12210-gd-dynamic-image-help/#findComment-47399 Share on other sites More sharing options...
.josh Posted June 19, 2006 Share Posted June 19, 2006 I put, "Do you like pussy?" lol Quote Link to comment https://forums.phpfreaks.com/topic/12210-gd-dynamic-image-help/#findComment-47400 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.