Jump to content

PHP GD Library images help...can I have it switch?


hlcornish

Recommended Posts

:shrug:

Hey guys, I have created combined images from edits I had laying around.  I have a chair, and i'm trying to combine different colored tops with a pair of legs using a radio button to choose the top color.  Here is what I have so far for the form page:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Untitled Document</title>
</head>

<body>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<label>Seat Color Choices:</label><br>
Red<input type="radio" name="color" value="red" id="red" onFocus="getElementById('config').src = 'red.php'" >
Orange<input type="radio" name="color" value="orange" id="orange" onFocus="getElementById('config').src = 'orange.php'" >
Ivory<input type="radio" name="color" value="ivory" id="ivory" onFocus="getElementById('config').src = 'ivory.php'" >
Black<input type="radio" name="color" value="black" id="black" onFocus="getElementById('config').src = 'black.php'" >
</form>

<img src="black.php" id="config" alt="color choice for lola chair">

</body>
</html>

 

...and here is one of my image files for an example:

<?php
//Report any errors
ini_set ("display_errors", "1");
error_reporting(E_ALL);

//Set the correct content type 
header('content-type: image/jpeg');


$base = imagecreatefromjpeg('lola_base.jpg');
$red = imagecreatefromgif('lola_red.gif');
$orange = imagecreatefromgif('lola_orange.gif');
$ivory = imagecreatefromgif('lola_ivory.gif');
$black = imagecreatefromgif('lola_black.gif');


imagecopy($base, $red, 0 , 0 , 0, 0,250, 250);

imagejpeg($base); 
//Clear up memory used

imagedestroy($base);

?>

 

The problem is, I need to be able to dynamically change which images are being combined.  I can't have a different file for each combo (ex. red.gif, black.gif, ivory.gif, etc.) I need it to create them on cue from a single file/function. Is there a way to do that with PHP GD library?

Link to comment
Share on other sites

Imagecopymerge does this I think.

 

It sounds as if you need to do a similar thing to watermarking - ie adding one image to another in a particular place on the background image. There are many different free  watermarking scripts available which may help or give you some ideas.

 

I would probably use some kind of ajax solution which calls a php program on click of a radio button, to merge the images how they want them and displays it back on the webpage.

 

 

Link to comment
Share on other sites

Maybe I need to clarify a little...or maybe i'm not understanding that what was posted would work for my need...

 

Lets say we're building a chair from 3 images. On the page is a default image, and 3 radio button menus.

Lets say I have a radio button menu for "top color".  It holds values red, ivory, black, orange. I have a gif image of each top in these colors.

I also have a menu called "base color".  I have color values black, white, brown for this menu. I have an image of each base (legs) in the three colors.

I have a menu called "arm color", with red, ivory, black, and orange.  I have images of the arms of the chair in each color.

 

I want to use imagecopy() to combine these images (one base, one top, one arm image) into a whole chair.  Not a problem, i've figured out how to combine them...I haven't used the gd library before but i'm picking it up okay.  The problem is, I need these images to combine and display according to the color combinations chosen in the 3 menus.  I have some combinations that would require too many images if they were made individually and then loaded.  So, I am trying to create/load them on the spot as the menu choices are submitted. 

 

Am I going to have to have a separate php gd file for each combination, and load the swtch with javascript or ajax? Or is there a way to write one file/function that will detect the submitted choices and create the image from the necessary pictures of the choices...then load it to change the default image on the page?  If i'm completely missing what was said in the former solution, feel free to smack me around.  My problem is I don't know how to go about writing the code to make it switch the way I need, and I also know absolutely zilch about ajax at this point, as a note.

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.