the-botman Posted December 2, 2009 Share Posted December 2, 2009 hi guys .. ok see i want the user to add their name and pick a number then click get it and it prints the name on top and the number bellow it on a t-shirt i just cant seem to get this rite i have no clue how to go about doing this please can you help me this is what i have so far <?php $ShowBookmark = "False"; include 'Include/Header.php'; if (Get_QString('Post') == "True") { Get_image(); } else { Show_Form(); } function Show_Form() { echo '<div class="hd2"><center><font color=#666666><strong>Soccer Kit Gen</strong></font></center></div><br>'."\n"; echo ' Name: <input type="text" name="name" /><br />'."\n"; echo ' <form method="post" action="test.php?Post=True">'."\n"; echo ' Number: <select name="number">'."\n"; echo ' <option value="0" selected="selected">0</option>'."\n"; echo ' <option value="1">1</option>'."\n"; echo ' <option value="2">2</option>'."\n"; echo ' <option value="3">3</option>'."\n"; echo ' <option value="4">4</option>'."\n"; echo ' <option value="5">5</option>'."\n"; echo ' <option value="6">6</option>'."\n"; echo ' <option value="7">7</option>'."\n"; echo ' <option value="8">8</option>'."\n"; echo ' <option value="9">9</option>'."\n"; echo ' <option value="10">10</option>'."\n"; echo ' <option value="11">11</option>'."\n"; echo ' <option value="12">12</option>'."\n"; echo ' <option value="13">13</option>'."\n"; echo ' <option value="14">14</option>'."\n"; echo ' <option value="15">15</option>'."\n"; echo ' <option value="16">16</option>'."\n"; echo ' <option value="17">17</option>'."\n"; echo ' <option value="18">18</option>'."\n"; echo ' <option value="19">19</option>'."\n"; echo ' <option value="20">20</option>'."\n"; echo ' <option value="21">21</option>'."\n"; echo ' <option value="22">22</option>'."\n"; echo ' <option value="23">23</option>'."\n"; echo ' <option value="24">24</option>'."\n"; echo ' <option value="25">25</option>'."\n"; echo ' <option value="26">26</option>'."\n"; echo ' <option value="27">27</option>'."\n"; echo ' <option value="28">28</option>'."\n"; echo ' <option value="29">29</option>'."\n"; echo ' <option value="30">30</option>'."\n"; echo ' <option value="31">31</option>'."\n"; echo ' <option value="21">32</option>'."\n"; echo ' <option value="22">33</option>'."\n"; echo ' <option value="23">34</option>'."\n"; echo ' <option value="24">35</option>'."\n"; echo ' <option value="25">36</option>'."\n"; echo ' <option value="26">37</option>'."\n"; echo ' <option value="27">38</option>'."\n"; echo ' <option value="28">39</option>'."\n"; echo ' <option value="29">40</option>'."\n"; echo ' <option value="30">41</option>'."\n"; echo ' <option value="31">42</option>'."\n"; echo ' <option value="30">43</option>'."\n"; echo ' <option value="31">44</option>'."\n"; echo ' </select>'; echo ' </td></tr>'."\n"; echo ' <tr><td colspan="2" align=center><br><input type="submit" value="Get It!" name="Submit"></td></tr>'."\n"; echo ' </table>'."\n"; echo '</form>'."\n"; Show_Buttons("True", "index.php?Cmd=100"); } function Get_image() { $number = GetPost('number'); $name = GetPost('name'); header("Content-Type: image/jpeg"); $im = ImageCreateFromGif("soccer-kit.png"); $black = ImageColorAllocate($im, 255, 255, 255); $start_x = 10; $start_y = 20; Imagettftext($im, 12, 0, $start_x, $start_y, $black, 'verdana.ttf', "$name"); //Creates the jpeg image and sends it to the browser //100 is the jpeg quality percentage Imagejpeg($im, '', 100); ImageDestroy($im); include 'Include/Footer.php'; Log_Hit("soccerkitgen"); ?> Quote Link to comment Share on other sites More sharing options...
cags Posted December 2, 2009 Share Posted December 2, 2009 Ok, first things first your numbers in your dropdown seem a bit 'skew-wiff' (the values don't match the number shown to the viewer). Also the code is waaaay longer than it need be. Replacing it all with something like... echo '<option value="0" selected="selected">0</option>'."\n"; for($i = 1; $i <= 44; ++$i) { echo '<option value="' . $i . '">' . $i . '</option>'."\n"; } Secondly the name input is outside the form, which I assume you don't want it to be. Move it down a line below the form declaration. Thirdly you don't appear to have any table opening tags (unless it's part of the header, but that would seem strange) so I have no idea why you have the closing tag or the <td><tr> etc, etc. Fourthly I've never heard of the functions Get_QString or GetPost so god knows what they are actually doing, I'm just going to assume they return values from the $_GET and $_POST array. I've also never heard of a Show_Buttons so I don't know what that does either. Fifthly, you don't appear to have a closing squiggly bracket for the Get_image() function, so I'm not sure if all the code below it is suppose to be a part of it or not. But I assume you should place one below imagedestroy, Sixthly the second parameter of imagejpeg should be null if you do not wish to use it, you are passing an empty string which is not the same thing it should simply say NULL (not in quotes, it's not a string it's essentialy a constant/language special meaning word). If you address those issues and post more details then perhaps I/we can provide more assistance. Quote Link to comment Share on other sites More sharing options...
the-botman Posted December 2, 2009 Author Share Posted December 2, 2009 thanks alot for pointing out my mistakes i have fixed most of them here is my code now the form works 100% just to get the name and number on the image <?php $ShowBookmark = "False"; include 'Include/Header.php'; if($_POST['name'] == True) { Get_image(); } else { Show_Form(); } function Show_Form() { echo '<div class="hd2"><center><font color=#666666><strong>Soccer Kit Gen</strong></font></center></div><br>'."\n"; echo ' <form method="post" action="test.php?Post=True">'."\n"; echo ' Name: <input type="text" name="name" /><br />'."\n"; echo ' Number: <select name="number">'."\n"; echo ' <option value="0" selected="selected">0</option>'."\n"; for($i = 1; $i <= 44; ++$i) { echo ' <option value="' . $i . '">' . $i . '</option>'."\n"; } echo ' </select>'; echo ' <tr><td colspan="2" align=center><br><input type="submit" value="Get It!" name="Submit"></td></tr>'."\n"; echo '</form>'."\n"; Show_Buttons("True", "index.php?Cmd=100"); } function Get_image() { $number = .$_POST['number']. $name = .$_POST['name']. header("Content-Type: image/jpeg"); $im = ImageCreateFromGif("soccer-kit.png"); $black = ImageColorAllocate($im, 255, 255, 255); $start_x = 10; $start_y = 20; Imagettftext($im, 12, 0, $start_x, $start_y, $black, 'verdana.ttf', "$name"); //Creates the jpeg image and sends it to the browser //100 is the jpeg quality percentage Imagejpeg($im, '', 100); ImageDestroy($im); } include 'Include/Footer.php'; Log_Hit("soccerkitgen"); ?> Quote Link to comment Share on other sites More sharing options...
cags Posted December 2, 2009 Share Posted December 2, 2009 I don't know what the objective of the periods/fullstops in the following are... $number = .$_POST['number']. $name = .$_POST['name']. But it should be... $number = $_POST['number']; $name = $_POST['name']; I notice your using ImageCreateFromGif when the filename has the extension .png, you should instead try using imagecreatefrompng. I also noticed you have the name of your colour variable as black, but the colour your actually using is white, you should use 0 for the attributes to get black. You still have an empty string as the second parameter of imagejpeg, I say again it should be NULL... imagejpeg($im, NULL, 100); If it doesn't work after changing that try commenting out the line with imagettftext on it and see if the image loads up without the text on it. Quote Link to comment Share on other sites More sharing options...
the-botman Posted December 2, 2009 Author Share Posted December 2, 2009 ok i have tried that also the form works fine and after i click enter it downloads an image but not the t-shirt with the name on it but just a blank image this is the code now <?php $ShowBookmark = "False"; include 'Include/Header.php'; if($_POST['name'] == True) { Get_image(); } else { Show_Form(); } function Show_Form() { echo '<div class="hd2"><center><font color=#666666><strong>Soccer Kit Gen</strong></font></center></div><br>'."\n"; echo ' <form method="post" action="test.php?Post=True">'."\n"; echo ' Name: <input type="text" name="name" /><br />'."\n"; echo ' Number: <select name="number">'."\n"; echo ' <option value="0" selected="selected">0</option>'."\n"; for($i = 1; $i <= 44; ++$i) { echo ' <option value="' . $i . '">' . $i . '</option>'."\n"; } echo ' </select>'; echo ' <tr><td colspan="2" align=center><br><input type="submit" value="Get It!" name="Submit"></td></tr>'."\n"; echo '</form>'."\n"; Show_Buttons("True", "index.php?Cmd=100"); } function Get_image() { $number = $_POST['number']; $name = $_POST['name']; header("Content-Type: image/jpeg"); $im = ImageCreateFromGif("soccer-kit.png"); $black = ImageColorAllocate($im, 255, 255, 255); $start_x = 10; $start_y = 20; Imagettftext($im, 12, 0, $start_x, $start_y, $black, 'verdana.ttf', "$name"); //Creates the jpeg image and sends it to the browser //100 is the jpeg quality percentage imagejpeg($im, NULL, 100); ImageDestroy($im); } include 'Include/Footer.php'; Log_Hit("soccerkitgen"); ?> thanks alot for all your help Quote Link to comment Share on other sites More sharing options...
cags Posted December 2, 2009 Share Posted December 2, 2009 And what happens if you comment out "Imagettftext($im, 12, 0, $start_x, $start_y, $black, 'verdana.ttf', "$name");" Quote Link to comment Share on other sites More sharing options...
the-botman Posted December 2, 2009 Author Share Posted December 2, 2009 same thing happens when i click get it downloads a blank image Quote Link to comment Share on other sites More sharing options...
cags Posted December 2, 2009 Share Posted December 2, 2009 You still using ImageCreateFromGif. Quote Link to comment Share on other sites More sharing options...
the-botman Posted December 2, 2009 Author Share Posted December 2, 2009 this is how i have it now but it still downloads a blank image <?php $ShowBookmark = "False"; include 'Include/Header.php'; if($_POST['name'] == True) { Get_image(); } else { Show_Form(); } function Show_Form() { echo '<div class="hd2"><center><font color=#666666><strong>Soccer Kit Gen</strong></font></center></div><br>'."\n"; echo ' <form method="post" action="test.php?Post=True">'."\n"; echo ' Name: <input type="text" name="name" /><br />'."\n"; echo ' Number: <select name="number">'."\n"; echo ' <option value="0" selected="selected">0</option>'."\n"; for($i = 1; $i <= 44; ++$i) { echo ' <option value="' . $i . '">' . $i . '</option>'."\n"; } echo ' </select>'; echo ' <tr><td colspan="2" align=center><br><input type="submit" value="Get It!" name="Submit"></td></tr>'."\n"; echo '</form>'."\n"; Show_Buttons("True", "index.php?Cmd=100"); } function Get_image() { $number = $_POST['number']; $name = $_POST['name']; header("Content-Type: image/jpeg"); $im = imagecreatefrompng("soccer-kit.png"); if(!$im) { die(""); } $black = ImageColorAllocate($im, 255, 255, 255); $start_x = 10; $start_y = 20; Imagettftext($im, 12, 0, $start_x, $start_y, $black, 'verdana.ttf', "$name"); //Creates the jpeg image and sends it to the browser //100 is the jpeg quality percentage imagejpeg($im, NULL, 100); ImageDestroy($im); } include 'Include/Footer.php'; Log_Hit("soccerkitgen"); ?> Quote Link to comment Share on other sites More sharing options...
cags Posted December 2, 2009 Share Posted December 2, 2009 I ran your code and upon commenting out the aforementioned line it displays an image. Do you have your error_reporting set correctly? Quote Link to comment Share on other sites More sharing options...
the-botman Posted December 2, 2009 Author Share Posted December 2, 2009 i think this is the problem echo ' <form method="post" action="test.php?Post=True">'."\n"; becuase the image is coming up as test.php?post=true Quote Link to comment Share on other sites More sharing options...
cags Posted December 2, 2009 Share Posted December 2, 2009 Well I did change that line to get it working, but thats because my file was called index.php. I changed it to "?Post=True", but to be honest with you I have no idea why Post=True is even included, you don't appear to be using it. Quote Link to comment Share on other sites More sharing options...
the-botman Posted December 2, 2009 Author Share Posted December 2, 2009 i have changed it to this code and now i get an image cald test.png <?php $ShowBookmark = "False"; include 'Include/Header.php'; if($_POST['name'] == True) { Get_image(); }else { Show_Form(); } function Show_Form() { echo '<div class="hd2"><center><font color=#666666><strong>Soccer Kit Generator</strong></font></center></div><br>'."\n"; echo ' <form method="post">'."\n"; echo ' Name: <input type="text" name="name" /><br />'."\n"; echo ' Number: <select name="number">'."\n"; echo ' <option value="0" selected="selected">0</option>'."\n"; for($i = 1; $i <= 44; ++$i) { echo ' <option value="' . $i . '">' . $i . '</option>'."\n"; } echo ' </select><br />'; echo ' <input type="submit" value="Submit" />'."\n"; } function Get_image() { $number = $_POST['number']; $name = $_POST['name']; header("Content-Type: image/png"); $im = imagecreatefrompng("soccer-kit.png"); if(!$im){ die("");} $black = ImageColorAllocate($im, 255, 255, 255); $start_x = 10; $start_y = 20; Imagettftext($im, 12, 0, $start_x, $start_y, $black, 'verdana.ttf', "$name"); //Creates the png image and sends it to the browser //100 is the png quality percentage imagepng($im, NULL, 100); ImageDestroy($im); } include 'Include/Footer.php'; Log_Hit("soccerkitgen"); ?> Quote Link to comment Share on other sites More sharing options...
the-botman Posted December 2, 2009 Author Share Posted December 2, 2009 anyone? 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.