Author Topic: [SOLVED] colour selection problem  (Read 248 times)

0 Members and 1 Guest are viewing this topic.

Offline AccuraxTopic starter

  • Enthusiast
    • View Profile
[SOLVED] colour selection problem
« on: May 31, 2007, 09:32:04 AM »
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
Code: [Select]
      <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
Code: [Select]
<?php


if(isset($_GET['phrase'])) {

// Set the content-type
header("Content-type: image/png");

$phrase stripslashes($_GET['phrase']);

// Create the image
$im imagecreatetruecolor(400100);

// Create some colors
$colour $_GET['colour'];
if (
$colour 'red') {
 
$col imagecolorallocate($im255000000);
}
elseif (
$colour 'pink') {
  $col imagecolorallocate($im255105180);
}
elseif (
$colour 'blue') {
  $col imagecolorallocate($im000000255);
}
else {
  $col imagecolorallocate($im000);
}


$white imagecolorallocate($im255255255);
$grey imagecolorallocate($im128128128);
$black imagecolorallocate($im000);

//create a border
imagefilledrectangle($im1139898$white);

// define the path to the selected font
$font $_GET['font'];

// Add the text
imagettftext($im2005050$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

Offline AccuraxTopic starter

  • Enthusiast
    • View Profile
Re: colour selection problem
« Reply #1 on: May 31, 2007, 10:10:30 AM »
its ok... it was a silly mistake i couldnt see, took a coffee break and ive got it.

how do i mark as solved?

Offline chrisprse

  • Enthusiast
    • View Profile
Re: colour selection problem
« Reply #2 on: May 31, 2007, 10:11:43 AM »
Try changing the first piece of code posted to:

Code: [Select]
<?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.

Offline frost110

  • Fanatic
  • Gender: Male
  • /dev/null
    • View Profile
    • PHP
Re: colour selection problem
« Reply #3 on: May 31, 2007, 10:20:52 AM »
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.
Note: I do not test most of my code before posting, be aware!!!!

 Looking for an Awesome FREE PHP Editor? Eclipse with PHP-IDE Plugin - Best I ever used!

PHP Freaks Forums

« on: »

Tired of these ads? Purchase a supporter subscription to get rid of them.