Jump to content


Photo

GD - dynamic image help.....


  • Please log in to reply
14 replies to this topic

#1 cwncool

cwncool
  • Members
  • PipPipPip
  • Advanced Member
  • 50 posts

Posted 16 June 2006 - 11:50 PM

I'm trying to make a script to create a new image from "http://www.gigacat.c...om/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.
<?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");
?>
on this first one i just end up with a blank, white page.

and this.
<?php
header("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");
?>
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!

#2 poirot

poirot
  • Members
  • PipPipPip
  • Advanced Member
  • 646 posts
  • LocationAustin, TX

Posted 17 June 2006 - 12:08 AM

Try to change:
imagejpeg($id,"newkitten.jpeg");
To
imagejpeg($id);

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]

~ D Kuang

#3 cwncool

cwncool
  • Members
  • PipPipPip
  • Advanced Member
  • 50 posts

Posted 17 June 2006 - 12:15 AM

i got it working (thanx), but is there a way to make the font size smaller? Thanx!


#4 poirot

poirot
  • Members
  • PipPipPip
  • Advanced Member
  • 646 posts
  • LocationAustin, TX

Posted 17 June 2006 - 12:17 AM

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]imagettftext ( resource image, float size, 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]
~ D Kuang

#5 cwncool

cwncool
  • Members
  • PipPipPip
  • Advanced Member
  • 50 posts

Posted 17 June 2006 - 12:27 AM

thanx. i tried that, but must have done something wrong! :) thanx for your help!

#6 cwncool

cwncool
  • Members
  • PipPipPip
  • Advanced Member
  • 50 posts

Posted 17 June 2006 - 09:01 PM

Okay. The script I have working now is....
<?php
header("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);
?>
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!

#7 cwncool

cwncool
  • Members
  • PipPipPip
  • Advanced Member
  • 50 posts

Posted 18 June 2006 - 04:52 PM

anybody?

#8 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 18 June 2006 - 04:55 PM

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' />
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#9 deadonarrival

deadonarrival
  • Members
  • PipPipPip
  • Advanced Member
  • 284 posts

Posted 18 June 2006 - 04:57 PM

<img src="page.php" />

should just work. page.php being this script.
DO {
$this->time_warp("Jump to the left","Step to the right","Bend knees in time");
} WHILE (2>1)

Warning: The above post may not make a lot of sense, and the sentence structure will suck. I tend to ramble a lot. Sorry ;-)

#10 cwncool

cwncool
  • Members
  • PipPipPip
  • Advanced Member
  • 50 posts

Posted 18 June 2006 - 05:42 PM

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?

#11 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 18 June 2006 - 05:48 PM

are you sure you don't have the image file as the action='..' in your form?
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#12 cwncool

cwncool
  • Members
  • PipPipPip
  • Advanced Member
  • 50 posts

Posted 18 June 2006 - 11:42 PM

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...
<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>
it just refreshes the page with the text entered in the top url of the form page, but does nothing to the image....

#13 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 19 June 2006 - 04:21 AM

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
<?php
if ($_GET['text']) {
   $text = $_GET['text'];
} else {
   $text = 'meow';
}

//build your image using $text
//and end it with the header
?>

form.php
<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>

Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#14 cwncool

cwncool
  • Members
  • PipPipPip
  • Advanced Member
  • 50 posts

Posted 19 June 2006 - 06:31 PM

that worked perfectly! :) :) Thanx Crayon!
[a href=\"http://www.gigacat.com/kitten.php\" target=\"_blank\"]here's the working script![/a]

#15 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 19 June 2006 - 06:37 PM

I put, "Do you like pussy?" lol
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users