Jump to content

PHP Based Img swap always turning up orange version???


hlcornish

Recommended Posts

:confused:

Hi guys,

I have written a page that contains a form.  When the user chooses a color, it is posted, then the posted value is re-written as a filename, sent through a function, and the image on the page uses the "colorized.gif" created by the function to make an image swap "onclick.  Problem is, no matter the choice, it always changes the picture to orange! Here is the code for the form:

 

<?php include('function.php'); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>PHP GD CONFIGURATOR</title>
</head>

<body>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
Red<input type="radio" name="color" value="red" />
Orange<input type="radio" name="color" value="orange" />
Ivory<input type="radio" name="color" value="ivory" />
Black<input type="radio" name="color" value="black" />
<input type="submit" name="submit" value="submit" />
</form>
<?php if($_POST['color'] != NULL){
echo $_POST['color']; 
	$file =('gdimages/' . $_POST['color'] . '.gif');
	createImg($file);
}
?>

<img src="default.jpg" name="lola" alt="lola dining chair" onclick="this.src = 'colorized.gif'" />
</body>
</html>

 

And here is the function...

 

function createImg ($imgname1)
{
$base = imagecreatefromgif("gdimages/base.gif");
$top = imagecreatefromgif($imgname1);

   if ($top) { 
       imagecopy($base, $top, 0, 0, 0, 0, 250, 250);
   imagejpeg($base, 'colorized.gif');
       imagedestroy($base);
   }
   else{
header("Content-Type: text/html");
}
   
}

 

I really can't understand it...this is my first attempt at programming something new by myself...and I really need it to work!!! I also plan for this to work with combining more than 2 images from more than two choice menus...so debugging now is definitely necessary. Any suggestions?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.