Accurax Posted May 31, 2007 Share Posted May 31, 2007 I have a script that allows a user to selecta phrase, a font, and a colour of that font and see it previewed in a window below the form. I cant seemt o gett he colour selection to work at all, at the moment it just keeps showing up in red. heres the script First the form <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <h2>Enter Your Phrase</h2> <input type="text" name="phrase" value="<?php if(isset($_POST["phrase"])) { echo $_POST["phrase"]; } ?>"/> <br /> <h2>Select Your Font</h2> <select name="font"> <option value="fonts/Adorable.ttf">Adorable</option> <option value="fonts/angelina.TTF">angelina</option> <option value="fonts/Ashley.ttf">Ashley</option> </select><br /> <h2>Select Your Color</h2> <select name="colour"> <option value="red" selected="selected" class="red">Red</option> <option value="pink" class="pink">Pink</option> <option value="blue" class="blue">Blue</option> </select><br /> <input type="submit" /><br /> </form> <?php if(isset($_POST["phrase"])) { $p = $_POST["phrase"]; $f = $_POST["font"]; $c = $_POST['colour']; echo "<img src=\"test2.php?phrase=$p&font=$f&colour=$c\" alt=\"\" />"; } ?> And now the script to create the image <?php if(isset($_GET['phrase'])) { // Set the content-type header("Content-type: image/png"); $phrase = stripslashes($_GET['phrase']); // Create the image $im = imagecreatetruecolor(400, 100); // Create some colors $colour = $_GET['colour']; if ($colour = 'red') { $col = imagecolorallocate($im, 255, 000, 000); } elseif ($colour = 'pink') { $col = imagecolorallocate($im, 255, 105, 180); } elseif ($colour = 'blue') { $col = imagecolorallocate($im, 000, 000, 255); } else { $col = imagecolorallocate($im, 0, 0, 0); } $white = imagecolorallocate($im, 255, 255, 255); $grey = imagecolorallocate($im, 128, 128, 128); $black = imagecolorallocate($im, 0, 0, 0); //create a border imagefilledrectangle($im, 1, 1, 398, 98, $white); // define the path to the selected font $font = $_GET['font']; // Add the text imagettftext($im, 20, 0, 50, 50, $col, $font, $phrase); // Using imagepng() results in clearer text compared with imagejpeg() imagepng($im); imagedestroy($im); } ?> Can anyone see what im doing wrong? .... my if statements look right to me..... but i cant get the result i expect. Any tips really appreciated on this.... thanks guys Link to comment https://forums.phpfreaks.com/topic/53729-solved-colour-selection-problem/ Share on other sites More sharing options...
Accurax Posted May 31, 2007 Author Share Posted May 31, 2007 its ok... it was a silly mistake i couldnt see, took a coffee break and ive got it. how do i mark as solved? Link to comment https://forums.phpfreaks.com/topic/53729-solved-colour-selection-problem/#findComment-265546 Share on other sites More sharing options...
chrisprse Posted May 31, 2007 Share Posted May 31, 2007 Try changing the first piece of code posted to: <?php if(isset($_POST)) { $phrase = $_POST['phrase']; $font = $_POST['font']; $colour = $_POST['colour']; } ?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <h2>Enter Your Phrase</h2> <input type="text" name="phrase" value="<?php if(isset($phrase)) { echo $phrase; } ?>"/> <br /> <h2>Select Your Font</h2> <select name="font"> <option value="fonts/Adorable.ttf">Adorable</option> <option value="fonts/angelina.TTF">angelina</option> <option value="fonts/Ashley.ttf">Ashley</option> </select> <br /> <h2>Select Your Color</h2> <select name="colour"> <option value="red" class="red">Red</option> <option value="pink" class="pink">Pink</option> <option value="blue" class="blue">Blue</option> </select> <br /> <input type="submit"/><br /> </form> <?php if(isset($phrase)) { $p = $phrase; $f = $font; $c = $colour; echo "<img src=\"test2.php?phrase=$p&font=$f&colour=$c\" alt=\"\" />"; } ?> Chris. Link to comment https://forums.phpfreaks.com/topic/53729-solved-colour-selection-problem/#findComment-265548 Share on other sites More sharing options...
per1os Posted May 31, 2007 Share Posted May 31, 2007 its ok... it was a silly mistake i couldnt see, took a coffee break and ive got it. how do i mark as solved? Bottom left hand corner. Link to comment https://forums.phpfreaks.com/topic/53729-solved-colour-selection-problem/#findComment-265559 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.