dragboatrandy
asked on
PHP and GD Library - Changing color of .png file and outlining it.
I posted this question in the graphics section, but thought maybe I would get a better answer in here.
I have a question that I have spent hours reading over posts and websites that have information about php and the GD Library. I have quite a few graphics that are .png files, that are only black and white. I need to be able to change the color of the black to a specified hexidecimal color within a form. I also need to outline that image with a hexidecimal color that is chosen from another form element. Is this possible? I have read that it is. Any help is greatly appreciated!
I have a question that I have spent hours reading over posts and websites that have information about php and the GD Library. I have quite a few graphics that are .png files, that are only black and white. I need to be able to change the color of the black to a specified hexidecimal color within a form. I also need to outline that image with a hexidecimal color that is chosen from another form element. Is this possible? I have read that it is. Any help is greatly appreciated!
ASKER
Basically what I do is I sell stickers and I want to be able to change the color using php instead of making 100 different versions of the same stickers to accomodate my color choices.
Sample Image: http://www.dragboats.com/images/merch/stickers/test.png
Your help is greatly appreciated.
Sample Image: http://www.dragboats.com/images/merch/stickers/test.png
Your help is greatly appreciated.
Here's an initial attempt:
<?php
$i = imagecreatefrompng('test.p ng');
if(($blackIndex = imagecolorexact($i, 0, 0, 0)) === -1) {
die('Black index not found');
}
imagecolorset($i, $blackIndex, 255, 0, 0); // change black to red
header('Content-type: image/png');
imagepng($i);
?>
It produces interesting results with your image - looks like there might be some grey shades around the edge?
If the edge was one colour and the fill another, you could set those colours independently (perhaps in response to your web form) using imagecolorexact (to isolate the indexes) and then imagecolorset (to change the colour).
<?php
$i = imagecreatefrompng('test.p
if(($blackIndex = imagecolorexact($i, 0, 0, 0)) === -1) {
die('Black index not found');
}
imagecolorset($i, $blackIndex, 255, 0, 0); // change black to red
header('Content-type: image/png');
imagepng($i);
?>
It produces interesting results with your image - looks like there might be some grey shades around the edge?
If the edge was one colour and the fill another, you could set those colours independently (perhaps in response to your web form) using imagecolorexact (to isolate the indexes) and then imagecolorset (to change the colour).
Ok, so
int imagecolorresolve ( resource image, int red, int green, int blue)
doesnt work as advertised, in fact its just as bad as 'imagecolorexact'. Instead,
int imagecolorclosest ( resource image, int red, int green, int blue)
is much better. Also, having a 256-colour image makes things a little difficult and off the top of my head I dont know how to find out what is the alpha channel, so if you were to re-export all the images as png-8, limit it to 8 to 16 colours and dont use transparancy they become a little easier to work with. Examples...
Original files -
Your original - http://www.cavey.co.uk/php/experts-exchange/images/test1.png
Without transparancy - http://www.cavey.co.uk/php/experts-exchange/images/test2.png
8-colour png - http://www.cavey.co.uk/php/experts-exchange/images/test3.png
Anyway, I made this page here -
http://www.cavey.co.uk/php/experts-exchange/make_ping2.php
which allows you to see what an image contains and then supply the arguments to the image creation script.
Quick example http://www.cavey.co.uk/php/experts-exchange/ping2.php?filename=test3.png&oldcolour0=ffffff&newcolour0=000000
Now from here it is totally possible to start doing elaborate scripting. Each time you add another oldcolourX=ffffff it will remove the next colour which is most "similar" to ffffff and replace it with the newcolourX, just a quesiton of feeding it the right info.
Source for ping2.php here - http://www.cavey.co.uk/php/experts-exchange/ping2.txt
int imagecolorresolve ( resource image, int red, int green, int blue)
doesnt work as advertised, in fact its just as bad as 'imagecolorexact'. Instead,
int imagecolorclosest ( resource image, int red, int green, int blue)
is much better. Also, having a 256-colour image makes things a little difficult and off the top of my head I dont know how to find out what is the alpha channel, so if you were to re-export all the images as png-8, limit it to 8 to 16 colours and dont use transparancy they become a little easier to work with. Examples...
Original files -
Your original - http://www.cavey.co.uk/php/experts-exchange/images/test1.png
Without transparancy - http://www.cavey.co.uk/php/experts-exchange/images/test2.png
8-colour png - http://www.cavey.co.uk/php/experts-exchange/images/test3.png
Anyway, I made this page here -
http://www.cavey.co.uk/php/experts-exchange/make_ping2.php
which allows you to see what an image contains and then supply the arguments to the image creation script.
Quick example http://www.cavey.co.uk/php/experts-exchange/ping2.php?filename=test3.png&oldcolour0=ffffff&newcolour0=000000
Now from here it is totally possible to start doing elaborate scripting. Each time you add another oldcolourX=ffffff it will remove the next colour which is most "similar" to ffffff and replace it with the newcolourX, just a quesiton of feeding it the right info.
Source for ping2.php here - http://www.cavey.co.uk/php/experts-exchange/ping2.txt
And just so a copy is stored at experts exchange, the source code is.....
<?php
header("Content-Type: text/plain");
function get_colour ($hex){
$color['r'] = hexdec(substr($hex,0,2));
$color['g'] = hexdec(substr($hex,2,2));
$color['b'] = hexdec(substr($hex,4,2));
return $color;
}
$filename = ( (isset($_GET['filename'])) ?$_GET['fi lename']:" test.png" );
$im = imagecreatefrompng("./imag es/".$_GET ['filename ']);
for ($i=0;isset($_GET['oldcolo ur'.$i]);$ i++){
$color = ( (isset($_GET['oldcolour'.$ i]))?$_GET ['oldcolou r'.$i]:"00 0000" );
$old_color = get_colour($color);
$color = ( (isset($_GET['newcolour'.$ i]))?$_GET ['newcolou r'.$i]:"FF 00FF" );
$new_color = get_colour($color);
$index = imagecolorclosest( $im, $old_color['r'], $old_color['g'], $old_color['b']);
imagecolorset ( $im, $index, $new_color['r'], $new_color['g'], $new_color['b']);
}
header("Content-type: image/png");
imagepng ($im);
imagedestroy($im);
?>
<?php
header("Content-Type: text/plain");
function get_colour ($hex){
$color['r'] = hexdec(substr($hex,0,2));
$color['g'] = hexdec(substr($hex,2,2));
$color['b'] = hexdec(substr($hex,4,2));
return $color;
}
$filename = ( (isset($_GET['filename']))
$im = imagecreatefrompng("./imag
for ($i=0;isset($_GET['oldcolo
$color = ( (isset($_GET['oldcolour'.$
$old_color = get_colour($color);
$color = ( (isset($_GET['newcolour'.$
$new_color = get_colour($color);
$index = imagecolorclosest( $im, $old_color['r'], $old_color['g'], $old_color['b']);
imagecolorset ( $im, $index, $new_color['r'], $new_color['g'], $new_color['b']);
}
header("Content-type: image/png");
imagepng ($im);
imagedestroy($im);
?>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you so much for your hard work. This is exactly what I am looking for. Now, I am pretty green on the implementation into my current page.
The current page is:
http://www.dragboats.com/merch/main_stickers1.php?ProductID=100056
I am transferring the color choices via form POST. I can easily change them to GET, but some fields within the form will be a little bit long.
When I put the code you provided into the page, I get a header already sent error.
Here is the code for the above page:
<?php require_once('../../Connec tions/conn DragboatAd min.php'); ?>
<?php require_once('../../Connec tions/conn DragboatUs er.php'); ?>
<?php
include("../../includes/me rch_colort able.php") ;
session_start();
$size = explode('_', $_POST['size_price']);
$_SESSION['Size'] = $size[0];
$_SESSION['size_price'] = $_POST['size_price'];
$pcolor = explode('~', $_POST['primary_color']);
$_SESSION['PColor'] = $pcolor[0];
$_SESSION['primary_color'] = $_POST['primary_color'];
$colname_rsStickers = "-1";
if (isset($_GET['ProductID']) ) {
$colname_rsStickers = (get_magic_quotes_gpc()) ? $_GET['ProductID'] : addslashes($_GET['ProductI D']);
}
mysql_select_db($database_ connDragbo atAdmin, $connDragboatAdmin);
$query_rsStickers = sprintf("SELECT * FROM Merch_Products WHERE ProductID = %s", $colname_rsStickers);
$rsStickers = mysql_query($query_rsStick ers, $connDragboatAdmin) or die(mysql_error());
$row_rsStickers = mysql_fetch_assoc($rsStick ers);
$totalRows_rsStickers = mysql_num_rows($rsStickers );
$colname_rsSizes = "-1";
if (isset($_GET['ProductID']) ) {
$colname_rsSizes = (get_magic_quotes_gpc()) ? $_GET['ProductID'] : addslashes($_GET['ProductI D']);
}
mysql_select_db($database_ connDragbo atUser, $connDragboatUser);
$query_rsSizes = sprintf("SELECT * FROM Merch_Sizes WHERE ProductID = %s ORDER BY SortOrder ASC", $colname_rsSizes);
$rsSizes = mysql_query($query_rsSizes , $connDragboatUser) or die(mysql_error());
$row_rsSizes = mysql_fetch_assoc($rsSizes );
$totalRows_rsSizes = mysql_num_rows($rsSizes);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html><!-- InstanceBegin template="/Templates/main_ 3.dwt" codeOutsideHTMLIsLocked="f alse" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<!-- InstanceBeginEditable name="doctitle" -->
<title>Untitled Document</title><!-- InstanceEndEditable -->
<link href="file:///Z|/Websites/ Dragboats2 /public_ht ml/main.cs s" rel="stylesheet" type="text/css">
</head>
<body>
<table width="1024" border="0" cellpadding="0" cellspacing="0" background="file:///Z|/Web sites/Drag boats2/pub lic_html/i mages/main _back_3.pn g">
<tr>
<td><img src="file:///Z|/Websites/D ragboats2/ public_htm l/images/m ain_r1c1.j pg" width="269" height="102"><img src="file:///Z|/Websites/D ragboats2/ public_htm l/images/m ain_r1c2.j pg" width="466" height="102"><img src="file:///Z|/Websites/D ragboats2/ public_htm l/images/m ain_r1c3.j pg" width="289" height="102"></td>
</tr>
<tr>
<td><img src="file:///Z|/Websites/D ragboats2/ public_htm l/images/m ain_r2c1.j pg" width="269" height="44"><img src="file:///Z|/Websites/D ragboats2/ public_htm l/images/m ain_r2c2.j pg" width="466" height="44"><img src="file:///Z|/Websites/D ragboats2/ public_htm l/images/m ain_r2c3.j pg" width="289" height="44"></td>
</tr>
<tr>
<td><a href="file:///Z|/Websites/ Dragboats2 /public_ht ml/index.p hp"></a><a href="file:///Z|/Websites/ Dragboats2 /public_ht ml/login.p hp"></a><a href="file:///Z|/Websites/ Dragboats2 /public_ht ml/classif ieds/class ifieds.php "></a><img src="file:///Z|/Websites/D ragboats2/ public_htm l/images/m ain_r3c1.p ng" width="117" height="17"><a href="file:///Z|/Websites/ Dragboats2 /public_ht ml/index.p hp"><img src="file:///Z|/Websites/D ragboats2/ public_htm l/images/m ain_r3c2_h ome.png" alt="Dragboats.com Homepage" width="43" height="17" border="0"></a><a href="file:///Z|/Websites/ Dragboats2 /public_ht ml/login.p hp"><img src="file:///Z|/Websites/D ragboats2/ public_htm l/images/m ain_r3c3_l ogin.png" alt="Account Login" width="47" height="17" border="0"></a><a href="file:///Z|/Websites/ Dragboats2 /public_ht ml/classif ieds/class ifieds.php "><img src="file:///Z|/Websites/D ragboats2/ public_htm l/images/m ain_r3c4_c lass.png" alt="Classifieds" width="83" height="17" border="0"></a><a href="file:///Z|/Websites/ Dragboats2 /public_ht ml/gallery /main.php" ><img src="file:///Z|/Websites/D ragboats2/ public_htm l/images/m ain_r3c5_p ics.png" alt="Photo Gallery" width="67" height="17" border="0"></a><a href="file:///Z|/Websites/ Dragboats2 /public_ht ml/merch/m ain.php">< img src="file:///Z|/Websites/D ragboats2/ public_htm l/images/m ain_r3c6_m erch.png" alt="Merchandise" width="93" height="17" border="0"></a><a href="file:///Z|/Websites/ Dragboats2 /public_ht ml/video/v ideo.php"> <img src="file:///Z|/Websites/D ragboats2/ public_htm l/images/m ain_r3c7_v ideo.png" alt="Videos" width="54" height="17" border="0"></a><img src="file:///Z|/Websites/D ragboats2/ public_htm l/images/m ain_r3c8_r esults.png " width="60" height="17"><a href="file:///Z|/Websites/ Dragboats2 /public_ht ml/schedul e.php"><im g src="file:///Z|/Websites/D ragboats2/ public_htm l/images/m ain_r3c9_s chedules.p ng" alt="Race Schedules" width="76" height="17" border="0"></a><img src="file:///Z|/Websites/D ragboats2/ public_htm l/images/m ain_r3c10_ profiles.p ng" width="69" height="17"><img src="file:///Z|/Websites/D ragboats2/ public_htm l/images/m ain_r3c11_ venues.png " width="54" height="17"><img src="file:///Z|/Websites/D ragboats2/ public_htm l/images/m ain_r3c12_ services.p ng" width="66" height="17"><a href="file:///Z|/Websites/ Dragboats2 /public_ht ml/contact .php"><img src="file:///Z|/Websites/D ragboats2/ public_htm l/images/m ain_r3c13_ contact.pn g" alt="Contact Us" width="82" height="17" border="0"></a><img src="file:///Z|/Websites/D ragboats2/ public_htm l/images/m ain_r3c14. png" width="113" height="17"></td>
</tr>
</table>
<!-- InstanceBeginEditable name="ContentArea" --><form action="" method="post" name="ColorSelect" id="ColorSelect"><table width="1024" border="0" cellpadding="0" cellspacing="0" background="file:///Z|/Web sites/Drag boats2/pub lic_html/i mages/main _back_3.pn g">
<tr>
<td colspan="7"><img src="file:///Z|/Websites/D ragboats2/ public_htm l/images/m ain_r4_3.p ng" width="1024" height="16" /></td>
</tr>
<tr>
<td width="18"> </td>
<td width="164" valign="top"><table width="160" border="0" cellpadding="0" cellspacing="0" background="../images/sm_d et_back.pn g">
<tr valign="bottom">
<td height="19" colspan="3" class="headingText"><table width="160" height="19" border="0" cellpadding="0" cellspacing="0" background="../images/sm_d et_top.png ">
<tr>
<td width="15"> </td>
<td width="135" valign="bottom" class="headingTextWhite">A VAILABLE SIZES </td>
<td width="10"> </td>
</tr>
</table></td>
</tr>
<tr>
<td colspan="3" class="headingText"><img src="../images/sm_det_r2.p ng" width="160" height="26" /></td>
</tr>
<tr>
<td width="10"> </td>
<td width="130"><?php do { ?>
<input name="size_price" type="radio" value="<?php $thisValue = $row_rsSizes['Size'].'_'.$ row_rsSize s['Price'] ; echo $thisValue; ?>" <?php if ($_POST['size_price'] == $thisValue) { echo 'checked'; } ?> onClick=ColorSelect.submit ()>
<span class="headingText"><?php echo $row_rsSizes['Size'].' - $'.$row_rsSizes['Price'];? ></span><b r>
<?php
} while ($row_rsSizes = mysql_fetch_assoc($rsSizes ));
$rows = mysql_num_rows($rsSizes);
if($rows > 0) {
mysql_data_seek($rsSizes, 0);
$row_rsSizes = mysql_fetch_assoc($rsSizes );
}
?>
<span class="smallTextLeft">
<input name="ProductID" type="hidden" id="ProductID" value="<?php echo $row_rsStickers['ProductID ']; ?>">
</span></td>
<td width="10"> </td>
</tr>
<tr>
<td> </td>
<td class="bodyText">You can order this sticker in any size you wish, for details call 1-866-29-Nitro </td>
<td> </td>
</tr>
<tr>
<td colspan="3"><img src="../images/sm_det_btm. png" width="160" height="10" /></td>
</tr>
</table>
<table width="160" border="0" cellpadding="0" cellspacing="0" background="../images/sm_d et_back.pn g">
<tr valign="bottom">
<td height="19" colspan="3" class="headingText"><table width="160" height="19" border="0" cellpadding="0" cellspacing="0" background="../images/sm_d et_top.png ">
<tr>
<td width="15"> </td>
<td width="135" valign="bottom" class="headingTextWhite">C URRENT CHOICES </td>
<td width="10"> </td>
</tr>
</table></td>
</tr>
<tr>
<td colspan="3" class="headingText"><img src="../images/sm_det_r2.p ng" width="160" height="26" /></td>
</tr>
<tr>
<td width="10"> </td>
<td width="130" class="headingText">Size:< /td>
<td width="10"> </td>
</tr>
<tr>
<td> </td>
<td class="bodyText"><?php if (!isset($_POST['size_price '])) { echo 'No Selected'; } else { $size = explode('_', $_POST['size_price']); echo $size[0]; } ?> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td class="headingText">Main Color:</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td class="bodyText"><?php if (!isset($_POST['primary_co lor'])) { echo 'Not Selected'; } else { $size = explode('~', $_POST['primary_color']); echo ucwords($size[0]);} ?></td>
<td> </td>
</tr>
<tr>
<td> </td>
<td class="headingText">Outlin e/Backgrou nd Color: </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td><span class="bodyText">
<?php if (!isset($_POST['primary_co lor'])) { echo 'Not Selected'; } else { $size = explode('~', $_POST['primary_color']); echo ucwords($size[0]);} ?>
</span></td>
<td> </td>
</tr>
<tr>
<td colspan="3"><img src="../images/sm_det_btm. png" width="160" height="10" /></td>
</tr>
</table> </td>
<td width="32"> </td>
<td width="595" align="right" valign="top">
<table width="595" border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="bodyTextCentered">< table border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td><img src="../images/adj_detail_ tl.png"></ td>
<td background="../images/adj_ detail_t.p ng"></td>
<td><img src="../images/adj_detail_ tr.png"></ td>
<td><img src="../images/adj_detail_ tl.png"></ td>
<td width="120" background="../images/adj_ detail_t.p ng"></td>
<td><img src="../images/adj_detail_ tr.png"></ td>
</tr>
<tr>
<td background="../images/adj_ detail_l.p ng"></td>
<td><img src="../images/merch/stick ers/<?php echo $row_rsStickers['PartNumbe r']; ?>.gif"></td>
<td background="../images/adj_ detail_r.p ng"></td>
<td background="../images/adj_ detail_l.p ng"></td>
<td width="120"><table width="120" border="0" cellspacing="0" cellpadding="5" bgcolor="<?php if (!isset($_POST['secondary_ color'])) { echo '000000'; } else {$secondaryColor = explode('~', $_POST['secondary_color']) ; echo $secondaryColor[1];} ?>">
<tr>
<td width="120"><table width="110" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="100" height="50" bgcolor="<?php if (!isset($_POST['primary_co lor'])) { echo '000000'; } else {$primaryColor = explode('~', $_POST['primary_color']); echo $primaryColor[1];} ?>"> </td>
</tr>
</table></td>
</tr>
</table></td>
<td background="../images/adj_ detail_r.p ng"></td>
</tr>
<tr>
<td><img src="../images/adj_detail_ bl.png"></ td>
<td background="../images/adj_ detail_b.p ng"></td>
<td><img src="../images/adj_detail_ br.png"></ td>
<td><img src="../images/adj_detail_ bl.png"></ td>
<td width="120" background="../images/adj_ detail_b.p ng"></td>
<td><img src="../images/adj_detail_ br.png"></ td>
</tr>
</table> </td>
</tr>
<tr>
<td class="bodyTextCentered">< table width="595" border="0" align="center" cellpadding="0" cellspacing="0" background="../images/med_ det_back.p ng">
<tr>
<td colspan="3"><table width="595" height="21" border="0" cellpadding="0" cellspacing="0" background="../images/med_ det_top.pn g">
<tr>
<td width="15"> </td>
<td width="565" class="headingTextWhite">M AIN STICKER COLOR </td>
<td width="15"> </td>
</tr>
</table></td>
</tr>
<tr>
<td colspan="3"><img src="../images/med_det_2.j pg" width="595" height="26" /></td>
</tr>
<tr>
<td width="15"> </td>
<td width="565" class="bodyTextCentered">< p>
<?php if (isset($_POST['primary_col or'])) { $primary_color = explode('~', $_POST['primary_color']); $selectedPrimaryColor = $primary_color[0]; } else { $selectedPrimaryColor = 'black'; } colorTable('primary_', $selectedPrimaryColor); ?>
</p></td>
<td width="15"> </td>
</tr>
<tr>
<td colspan="3"><img src="../images/med_det_btm .png" width="595" height="10" /></td>
</tr>
</table> </td>
</tr>
<tr>
<td><span class="bodyTextCentered">
</span>
<table width="595" border="0" align="center" cellpadding="0" cellspacing="0" background="../images/med_ det_back.p ng">
<tr>
<td colspan="3"><table width="595" height="21" border="0" cellpadding="0" cellspacing="0" background="../images/med_ det_top.pn g">
<tr>
<td width="15"> </td>
<td width="565" class="headingTextWhite">O UTLINE/BAC KGROUND COLOR </td>
<td width="15"> </td>
</tr>
</table></td>
</tr>
<tr>
<td colspan="3"><img src="../images/med_det_2.j pg" width="595" height="26" /></td>
</tr>
<tr>
<td width="15"> </td>
<td width="565" class="bodyTextCentered">< p>
<?php if (isset($_POST['primary_col or'])) { $secondary_color = explode('~', $_POST['secondary_color']) ; $selectedSecondaryColor = $secondary_color[0]; } else { $selectedSecondaryColor = ''; } if (isset($_POST['primary_col or'])) {colorTable('secondary_', $selectedSecondaryColor);} ?>
</p></td>
<td width="15"> </td>
</tr>
<tr>
<td colspan="3"><img src="../images/med_det_btm .png" width="595" height="10" /></td>
</tr>
</table>
</td>
</tr>
</table>
<span class="bodyTextCentered">
<input name="ProductID2" type="hidden" value="<?php if (isset($_POST['ProductID'] )) { echo $_POST['ProductID']; } if (isset($_GET['ProductID']) ) { echo $_GET['ProductID']; }?>">
</span><span class="bodyTextCentered">
<input name="SizePrice" type="hidden" value="<?php echo $_POST['SizePrice']; ?>">
</span></td>
<td width="32"> </td>
<td width="165" valign="top"><table width="160" border="0" cellpadding="0" cellspacing="0" background="file:///Z|/Web sites/Drag boats2/pub lic_html/i mages/sm_d et_back.pn g">
<tr valign="bottom">
<td height="19" colspan="3" class="headingText"><table width="160" height="19" border="0" cellpadding="0" cellspacing="0" background="file:///Z|/Web sites/Drag boats2/pub lic_html/i mages/sm_d et_top.png ">
<tr>
<td width="15"> </td>
<td width="135" valign="bottom" class="headingTextWhite">Y our Text Here </td>
<td width="10"> </td>
</tr>
</table></td>
</tr>
<tr>
<td colspan="3" class="headingText"><img src="file:///Z|/Websites/D ragboats2/ public_htm l/images/s m_det_r2.p ng" width="160" height="26" /></td>
</tr>
<tr>
<td width="10"> </td>
<td width="130"> </td>
<td width="10"> </td>
</tr>
<tr>
<td colspan="3"><img src="file:///Z|/Websites/D ragboats2/ public_htm l/images/s m_det_btm. png" width="160" height="10" /></td>
</tr>
</table></td>
<td width="18"> </td>
</tr>
<tr>
<td colspan="7"><img src="file:///Z|/Websites/D ragboats2/ public_htm l/images/m ain_btm_3. png" width="1024" height="26" /></td>
</tr>
</table>
</form>
<!-- InstanceEndEditable -->
</body>
<!-- InstanceEnd --></html>
Also, I would like to change the background of the sample to black or white based on a radio button. I don't know if I can just create a background table and color it the appropriate color?
You have been a tremendous help - much appreciated!
Randy
The current page is:
http://www.dragboats.com/merch/main_stickers1.php?ProductID=100056
I am transferring the color choices via form POST. I can easily change them to GET, but some fields within the form will be a little bit long.
When I put the code you provided into the page, I get a header already sent error.
Here is the code for the above page:
<?php require_once('../../Connec
<?php require_once('../../Connec
<?php
include("../../includes/me
session_start();
$size = explode('_', $_POST['size_price']);
$_SESSION['Size'] = $size[0];
$_SESSION['size_price'] = $_POST['size_price'];
$pcolor = explode('~', $_POST['primary_color']);
$_SESSION['PColor'] = $pcolor[0];
$_SESSION['primary_color']
$colname_rsStickers = "-1";
if (isset($_GET['ProductID'])
$colname_rsStickers = (get_magic_quotes_gpc()) ? $_GET['ProductID'] : addslashes($_GET['ProductI
}
mysql_select_db($database_
$query_rsStickers = sprintf("SELECT * FROM Merch_Products WHERE ProductID = %s", $colname_rsStickers);
$rsStickers = mysql_query($query_rsStick
$row_rsStickers = mysql_fetch_assoc($rsStick
$totalRows_rsStickers = mysql_num_rows($rsStickers
$colname_rsSizes = "-1";
if (isset($_GET['ProductID'])
$colname_rsSizes = (get_magic_quotes_gpc()) ? $_GET['ProductID'] : addslashes($_GET['ProductI
}
mysql_select_db($database_
$query_rsSizes = sprintf("SELECT * FROM Merch_Sizes WHERE ProductID = %s ORDER BY SortOrder ASC", $colname_rsSizes);
$rsSizes = mysql_query($query_rsSizes
$row_rsSizes = mysql_fetch_assoc($rsSizes
$totalRows_rsSizes = mysql_num_rows($rsSizes);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html><!-- InstanceBegin template="/Templates/main_
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<!-- InstanceBeginEditable name="doctitle" -->
<title>Untitled Document</title><!-- InstanceEndEditable -->
<link href="file:///Z|/Websites/
</head>
<body>
<table width="1024" border="0" cellpadding="0" cellspacing="0" background="file:///Z|/Web
<tr>
<td><img src="file:///Z|/Websites/D
</tr>
<tr>
<td><img src="file:///Z|/Websites/D
</tr>
<tr>
<td><a href="file:///Z|/Websites/
</tr>
</table>
<!-- InstanceBeginEditable name="ContentArea" --><form action="" method="post" name="ColorSelect" id="ColorSelect"><table width="1024" border="0" cellpadding="0" cellspacing="0" background="file:///Z|/Web
<tr>
<td colspan="7"><img src="file:///Z|/Websites/D
</tr>
<tr>
<td width="18"> </td>
<td width="164" valign="top"><table width="160" border="0" cellpadding="0" cellspacing="0" background="../images/sm_d
<tr valign="bottom">
<td height="19" colspan="3" class="headingText"><table
<tr>
<td width="15"> </td>
<td width="135" valign="bottom" class="headingTextWhite">A
<td width="10"> </td>
</tr>
</table></td>
</tr>
<tr>
<td colspan="3" class="headingText"><img src="../images/sm_det_r2.p
</tr>
<tr>
<td width="10"> </td>
<td width="130"><?php do { ?>
<input name="size_price" type="radio" value="<?php $thisValue = $row_rsSizes['Size'].'_'.$
<span class="headingText"><?php echo $row_rsSizes['Size'].' - $'.$row_rsSizes['Price'];?
<?php
} while ($row_rsSizes = mysql_fetch_assoc($rsSizes
$rows = mysql_num_rows($rsSizes);
if($rows > 0) {
mysql_data_seek($rsSizes, 0);
$row_rsSizes = mysql_fetch_assoc($rsSizes
}
?>
<span class="smallTextLeft">
<input name="ProductID" type="hidden" id="ProductID" value="<?php echo $row_rsStickers['ProductID
</span></td>
<td width="10"> </td>
</tr>
<tr>
<td> </td>
<td class="bodyText">You can order this sticker in any size you wish, for details call 1-866-29-Nitro </td>
<td> </td>
</tr>
<tr>
<td colspan="3"><img src="../images/sm_det_btm.
</tr>
</table>
<table width="160" border="0" cellpadding="0" cellspacing="0" background="../images/sm_d
<tr valign="bottom">
<td height="19" colspan="3" class="headingText"><table
<tr>
<td width="15"> </td>
<td width="135" valign="bottom" class="headingTextWhite">C
<td width="10"> </td>
</tr>
</table></td>
</tr>
<tr>
<td colspan="3" class="headingText"><img src="../images/sm_det_r2.p
</tr>
<tr>
<td width="10"> </td>
<td width="130" class="headingText">Size:<
<td width="10"> </td>
</tr>
<tr>
<td> </td>
<td class="bodyText"><?php if (!isset($_POST['size_price
<td> </td>
</tr>
<tr>
<td> </td>
<td class="headingText">Main Color:</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td class="bodyText"><?php if (!isset($_POST['primary_co
<td> </td>
</tr>
<tr>
<td> </td>
<td class="headingText">Outlin
<td> </td>
</tr>
<tr>
<td> </td>
<td><span class="bodyText">
<?php if (!isset($_POST['primary_co
</span></td>
<td> </td>
</tr>
<tr>
<td colspan="3"><img src="../images/sm_det_btm.
</tr>
</table> </td>
<td width="32"> </td>
<td width="595" align="right" valign="top">
<table width="595" border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="bodyTextCentered"><
<tr>
<td><img src="../images/adj_detail_
<td background="../images/adj_
<td><img src="../images/adj_detail_
<td><img src="../images/adj_detail_
<td width="120" background="../images/adj_
<td><img src="../images/adj_detail_
</tr>
<tr>
<td background="../images/adj_
<td><img src="../images/merch/stick
<td background="../images/adj_
<td background="../images/adj_
<td width="120"><table width="120" border="0" cellspacing="0" cellpadding="5" bgcolor="<?php if (!isset($_POST['secondary_
<tr>
<td width="120"><table width="110" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="100" height="50" bgcolor="<?php if (!isset($_POST['primary_co
</tr>
</table></td>
</tr>
</table></td>
<td background="../images/adj_
</tr>
<tr>
<td><img src="../images/adj_detail_
<td background="../images/adj_
<td><img src="../images/adj_detail_
<td><img src="../images/adj_detail_
<td width="120" background="../images/adj_
<td><img src="../images/adj_detail_
</tr>
</table> </td>
</tr>
<tr>
<td class="bodyTextCentered"><
<tr>
<td colspan="3"><table width="595" height="21" border="0" cellpadding="0" cellspacing="0" background="../images/med_
<tr>
<td width="15"> </td>
<td width="565" class="headingTextWhite">M
<td width="15"> </td>
</tr>
</table></td>
</tr>
<tr>
<td colspan="3"><img src="../images/med_det_2.j
</tr>
<tr>
<td width="15"> </td>
<td width="565" class="bodyTextCentered"><
<?php if (isset($_POST['primary_col
</p></td>
<td width="15"> </td>
</tr>
<tr>
<td colspan="3"><img src="../images/med_det_btm
</tr>
</table> </td>
</tr>
<tr>
<td><span class="bodyTextCentered">
</span>
<table width="595" border="0" align="center" cellpadding="0" cellspacing="0" background="../images/med_
<tr>
<td colspan="3"><table width="595" height="21" border="0" cellpadding="0" cellspacing="0" background="../images/med_
<tr>
<td width="15"> </td>
<td width="565" class="headingTextWhite">O
<td width="15"> </td>
</tr>
</table></td>
</tr>
<tr>
<td colspan="3"><img src="../images/med_det_2.j
</tr>
<tr>
<td width="15"> </td>
<td width="565" class="bodyTextCentered"><
<?php if (isset($_POST['primary_col
</p></td>
<td width="15"> </td>
</tr>
<tr>
<td colspan="3"><img src="../images/med_det_btm
</tr>
</table>
</td>
</tr>
</table>
<span class="bodyTextCentered">
<input name="ProductID2" type="hidden" value="<?php if (isset($_POST['ProductID']
</span><span class="bodyTextCentered">
<input name="SizePrice" type="hidden" value="<?php echo $_POST['SizePrice']; ?>">
</span></td>
<td width="32"> </td>
<td width="165" valign="top"><table width="160" border="0" cellpadding="0" cellspacing="0" background="file:///Z|/Web
<tr valign="bottom">
<td height="19" colspan="3" class="headingText"><table
<tr>
<td width="15"> </td>
<td width="135" valign="bottom" class="headingTextWhite">Y
<td width="10"> </td>
</tr>
</table></td>
</tr>
<tr>
<td colspan="3" class="headingText"><img src="file:///Z|/Websites/D
</tr>
<tr>
<td width="10"> </td>
<td width="130"> </td>
<td width="10"> </td>
</tr>
<tr>
<td colspan="3"><img src="file:///Z|/Websites/D
</tr>
</table></td>
<td width="18"> </td>
</tr>
<tr>
<td colspan="7"><img src="file:///Z|/Websites/D
</tr>
</table>
</form>
<!-- InstanceEndEditable -->
</body>
<!-- InstanceEnd --></html>
Also, I would like to change the background of the sample to black or white based on a radio button. I don't know if I can just create a background table and color it the appropriate color?
You have been a tremendous help - much appreciated!
Randy
For a start, replace
$im = imagecreatefrompng("./imag es/".$_GET ['filename ']);
with
$type = exif_imagetype ("./images/".$_GET['filena me']);
switch($type){
/*
1 = IMAGETYPE_GIF, 2 = IMAGETYPE_JPEG, 3 = IMAGETYPE_PNG, 4 = IMAGETYPE_SWF,
5 = IMAGETYPE_PSD, 6 = IMAGETYPE_BMP, 7 = IMAGETYPE_TIFF_II (intel byte order),
8 = IMAGETYPE_TIFF_MM (motorola byte order), 9 = IMAGETYPE_JPC, 10 = IMAGETYPE_JP2,
11 = IMAGETYPE_JPX, and 12 = IMAGETYPE_SWC
*/
default:
die("Incompatible file type");
break;
case 1:
$im = imagecreatefromgif("./imag es/".$_GET ['filename ']);
break;
case 2:
$im = imagecreatefromjpeg("./ima ges/".$_GE T['filenam e']);
break;
case 3:
$im = imagecreatefrompng("./imag es/".$_GET ['filename ']);
break;
case 6:
$im = imagecreatefromwbmp("./ima ges/".$_GE T['filenam e']);
break;
}
so that it can handle gif and jpeg files.
And personally, I'd stick with GET and update the image via a javascript as it would look cooler instead of the whole page refreshing
Example - http://www.cavey.co.uk/php/experts-exchange/make_ping4b.php
Failing that, change the GET/POST to REQUEST and it will use whichever you supply.
But remember - the request for the image is a new and unique request. The posts wont be forwarded on to the images in the page, so you would have to do them yourself.
And changing the background colour should be as easy as setting an ID on the td or div that you want to change the colour of then use
document.getElementById("i d").backgr ound-color = "#ffffff"
or whatever. Hope that helps, and I recommend starting a new question if you need anything else, cause I probably wont come back to this one.....
$im = imagecreatefrompng("./imag
with
$type = exif_imagetype ("./images/".$_GET['filena
switch($type){
/*
1 = IMAGETYPE_GIF, 2 = IMAGETYPE_JPEG, 3 = IMAGETYPE_PNG, 4 = IMAGETYPE_SWF,
5 = IMAGETYPE_PSD, 6 = IMAGETYPE_BMP, 7 = IMAGETYPE_TIFF_II (intel byte order),
8 = IMAGETYPE_TIFF_MM (motorola byte order), 9 = IMAGETYPE_JPC, 10 = IMAGETYPE_JP2,
11 = IMAGETYPE_JPX, and 12 = IMAGETYPE_SWC
*/
default:
die("Incompatible file type");
break;
case 1:
$im = imagecreatefromgif("./imag
break;
case 2:
$im = imagecreatefromjpeg("./ima
break;
case 3:
$im = imagecreatefrompng("./imag
break;
case 6:
$im = imagecreatefromwbmp("./ima
break;
}
so that it can handle gif and jpeg files.
And personally, I'd stick with GET and update the image via a javascript as it would look cooler instead of the whole page refreshing
Example - http://www.cavey.co.uk/php/experts-exchange/make_ping4b.php
Failing that, change the GET/POST to REQUEST and it will use whichever you supply.
But remember - the request for the image is a new and unique request. The posts wont be forwarded on to the images in the page, so you would have to do them yourself.
And changing the background colour should be as easy as setting an ID on the td or div that you want to change the colour of then use
document.getElementById("i
or whatever. Hope that helps, and I recommend starting a new question if you need anything else, cause I probably wont come back to this one.....
Example -
Dynamic image - http://www.cavey.co.uk/php/experts-exchange/ping.php?oldcolor=000000&newcolor=FFFF00
Original image - http://www.cavey.co.uk/php/experts-exchange/ping1.png
Change oldcolor to 000000 or ffffff to select which area to fill and newcolor to any hex colour you fancy.
Source code is here - http://www.cavey.co.uk/php/experts-exchange/ping.txt.