Hey guys, I'm new here. x)
I'm very much a noob when it comes to PHP, but I'm trying to learn as much as I can. I've been writing a script which will generate a new image after submitting some hex codes, using these hex codes to generate certain colored parts of the image. Everything works just dandy - when you first visit the page, the values in the boxes specify the original hex codes that identify the color that is being changed. So, when you put in a new value and submit it, the page refreshes and displays those new values. I store these values in variables, and so in the script that generates the image, call the hex codes that a) need to be changed and b) replace the old hex codes. Unfortunately, the only problem is that it isn't actually changing the colors.
So I'm not really sure how to use variables to obtain these old and new hex codes.
demo.php (this is the image generating script)
Code: [Select]<?
$line = imagecreatefrompng('/images/character/etw/etwmaleline.png');
$base = imagecreatefrompng('/images/character/etw/etwmalebase.png');
$base2 = imagecreatefrompng('/images/character/etw/etwmale2base.png');
$eyes = imagecreatefrompng('/images/character/etw/etwmaleeyes.png');
$statc = imagecreatefrompng('/images/character/etw/etwmalestatc.png');
//BASE hex
$width = imagesx($base);
$height = imagesy($base);
$colorToChange = $pbase;
$newbaseColor = $_GET['base'];
$c1 = sscanf($colorToChange,"%2x%2x%2x");
$c2 = sscanf($newbaseColor,"%2x%2x%2x");
$cnew = imagecolorallocate($base,$c2[0],$c2[1],$c2[2]);
for ($y=0;$y<$height;$y++) {
for ($x=0;$x<$width;$x++) {
$rgb = imagecolorat($base,$x,$y);
$r = ($rgb >> 16) & 0xFF;
$g = ($rgb >> 8) & 0xFF;
$b = $rgb & 0xFF;
if (($r==$c1[0]) && ($g==$c1[1]) && ($b==$c1[2])) {
imagesetpixel($base,$x,$y,$cnew);
}
}
}
//BASE2 hex
$width = imagesx($base2);
$height = imagesy($base2);
$colorToChange = $pbase2;
$newbase2Color = $_GET['base2'];
$c1 = sscanf($colorToChange,"%2x%2x%2x");
$c2 = sscanf($newbase2Color,"%2x%2x%2x");
$cnew = imagecolorallocate($base2,$c2[0],$c2[1],$c2[2]);
for ($y=0;$y<$height;$y++) {
for ($x=0;$x<$width;$x++) {
$rgb = imagecolorat($base2,$x,$y);
$r = ($rgb >> 16) & 0xFF;
$g = ($rgb >> 8) & 0xFF;
$b = $rgb & 0xFF;
if (($r==$c1[0]) && ($g==$c1[1]) && ($b==$c1[2])) {
imagesetpixel($base2,$x,$y,$cnew);
}
}
}
//EYES hex
$width = imagesx($eyes);
$height = imagesy($eyes);
$colorToChange = $peyes;
$neweyesColor = $_GET['eyes'];
$c1 = sscanf($colorToChange,"%2x%2x%2x");
$c2 = sscanf($neweyesColor,"%2x%2x%2x");
$cnew = imagecolorallocate($eyes,$c2[0],$c2[1],$c2[2]);
for ($y=0;$y<$height;$y++) {
for ($x=0;$x<$width;$x++) {
$rgb = imagecolorat($eyes,$x,$y);
$r = ($rgb >> 16) & 0xFF;
$g = ($rgb >> 8) & 0xFF;
$b = $rgb & 0xFF;
if (($r==$c1[0]) && ($g==$c1[1]) && ($b==$c1[2])) {
imagesetpixel($eyes,$x,$y,$cnew);
}
}
}
imagealphablending($line, 1);
imagealphablending($base, 1);
imagealphablending($base2, 1);
imagealphablending($eyes, 1);
imagealphablending($statc, 1);
$i= array($base, $eyes, $base2, $statc, $line);
$s = imagemergealpha($i);
//Merge multiple images and keep transparency
//$i is and array of the images to be merged:
// $i[1] will be overlayed over $i[0]
// $i[2] will be overlayed over that
// ...
//the function returns the resulting image ready for saving
function imagemergealpha($i) {
//create a new image
$s = imagecreatetruecolor(imagesx($i[0]),imagesy($i[1]));
//merge all images
imagealphablending($s,true);
$z = $i;
while($d = each($z)) {
imagecopy($s,$d[1],0,0,0,0,imagesx($d[1]),imagesy($d[1]));
}
//restore the transparency
imagealphablending($s,false);
$w = imagesx($s);
$h = imagesy($s);
for($x=0;$x<$w;$x++) {
for($y=0;$y<$h;$y++) {
$c = imagecolorat($s,$x,$y);
$c = imagecolorsforindex($s,$c);
$z = $i;
$t = 0;
while($d = each($z)) {
$ta = imagecolorat($d[1],$x,$y);
$ta = imagecolorsforindex($d[1],$ta);
$t += 127-$ta['alpha'];
}
$t = ($t > 127) ? 127 : $t;
$t = 127-$t;
$c = imagecolorallocatealpha($s,$c['red'],$c['green'],$c['blue'],$t);
imagesetpixel($s,$x,$y,$c);
}
}
imagesavealpha($s,true);
return $s;
}
header('Content-type: image/png');
imagepng($s);
imagedestroy($s);
error_reporting(E_ALL);
?>
hextest2.php
Code: [Select]<?php
include_once('test2.php');
$pbase = 'c8c8c8';
$pbase2 = 'c8c8c8';
$peyes = 'c8c8c8';
if (!isset($_GET['preview']) && !isset($_GET['submit']))
echo "thou hast naught yet submat thee hex codes!";
elseif (isset($_GET['preview']) && !isset($_GET['submit']))
include_once('test3.php');
else (
include_once('test4.php'));
?>
<html>
<head>
<title>Soundtrack Howl!</title>
<link rel="stylesheet" type="text/css" />
</head>
<body style="background-color: #d8d8d8;"> <center>
<table width="700px"> <tr> <td width="400px">
<img src="demo.php"/>
</td> </tr>
<tr> <td width="300px">
<form action="<?=$_SERVER['PHP_SELF']?>" method="get">
<b>Base:</b> # <input type="text" name="base" value="<? echo($pbase); ?>" /> <br />
<b>2nd Base:</b> # <input type="text" name="base2" value="<? echo($pbase2); ?>" /> <br />
<b>Eyes:</b> # <input type="text" name="eyes" value="<? echo($peyes); ?>" /> <br />
<input type="submit" name="preview" value="Preview Character!" /> <br /> <br />
<input type="submit" name="submit" value="Make Your New Character!!" />
</form>
</td> </tr> </table>
</center>
</body>
</html>
test3.php
Code: [Select]<?php
include_once('./includes/general.php');
if ($_GET['base']=='' or $_GET['base2']=='' or $_GET['eyes']==''){
echo "You haven't filled them all out! <br />";
}
if (strlen($_GET['base'])<'6' || strlen($_GET['base2'])<'6' || strlen($_GET['eyes'])<'6'){
echo "The hex codes are incomplete! <br />";
}
else {
$pbase = $_GET['base'];
$pbase2 = $_GET['base2'];
$peyes = $_GET['eyes'];
}
?>
test4.php
Code: [Select]<?php
include_once('./includes/general.php');
if ($_GET['base']=='' or $_GET['base2']=='' or $_GET['eyes']==''){
echo "You haven't filled them all out!";
}
else {
$nbase = $_GET['base'];
$nbase2 = $_GET['base2'];
$neyes = $_GET['eyes'];
$sql = mysql_query("INSERT INTO `character` (`base`, `base2`, `eyes`)
VALUES ('$nbase', '$nbase2', '$neyes') ") or die("Thou has submat thee hex codes! There be errors abreast!<br />".mysql_error());
header('Location: complete.php');
}
?>
And /includes/general.php is just the file that connects to the database.
I'm SO sorry, I know it's a ton of stuff to read, but I want to make sure the problem isn't just in demo.php. Also, I'm aware that my script(s) are messy and may have some unnecessary coding, so just ignore that unless it has anything to do with my problem XD To clarify, I did not actually literally write the image generating script all by myself. I used php.net and googled some stuff to reference.
Thanks
Displaying values from a SQL count...
Hi,Easy enough question i just forget the exact method ..I have ...Code: //count wins ...$count_wins = mysql_query("SELECT count(*) FROM `matches` WHERE result = 'W'AND Player1_ID =
Basic Question about Threading and PHP...
I have a page that I am working on and it is taking several hours to process. The basics of what the page does is get all the items out of a database then with cURL download some HTML parse through
How can use this array as a key?
Say I have this array for example:print_r($array);Prints:Code: [Select]Array( [0] => Array ( [status] => 0 ) [1] => Array (
Checking if multidimensional array is empty?
I have a for with multiple test input fields. Specifically the user submits multiple names and ages. The form is submitted using the POST method. Here is a code snippet:Code: <form action =
Looping Problem
I've got a client that has a database with about 200 events at any given time. I'm trying to loop through the dates based on a form and show the title of the event if the start date of the form
image upload, resize THEN submit form
Ok so I have a form that requires the user to upload an image, and then do something with that image (using some ajax scripts), then fill out the rest of the form and submit. I have the upload script
Preg_match unknown modifyer
Hello,Im trying to write a little script for my forums i need to get the reply from my forums. Im trying thisCode: $pattern = '/<span
this code is not working????
it says this error.. Warning: Division by zero in ..the variables are correct, so why is the variable $max zero??/Code: $sw = $_GET['w']; $sh = $_GET['h'];
Changes to hosting company's server has affected web contact form
I started a thread a couple of months ago about the contact forms on my client's website. Basically he wants me to overhaul the SEO on his site. However, there were problems with the PHP contact forms
mod_rewrite.c on windows ??
why it's not working on windows while it's working on other hosts??? this is the code i got from a tutorial :Code: [Select]<IfModule mod_rewrite.c>RewriteEngine OnRewriteBase