I have a problem which is making me code blind, When I call this script from client via xmlhttp the response should just be a file path string, instead I get an "endless" stream which of course I cannot view because status 4 is never returned. This is necessarily a synchronous call I am including only the code for the called script, as I get the same result no matter where I call it from. I hope someone has an answer, I am totally befuddled at this point! Thx ahead!
PHP Code:
<?php
include $_SERVER['DOCUMENT_ROOT']."ConnectString.php";
$ClientID = $_COOKIE["Brag_Flag_user"];
$TxtFldCnt = $_GET["TxtFldCnt"];
$TextString = $_GET["TextString"];
$Texts = split(",",$TextString);
//Get Project Info
$SQL="Select * From Projects where ClientID = $ClientID and Status = 'Current'";
$ProjectInfo = mysql_query($SQL);
$Info = mysql_fetch_array($ProjectInfo);
//Scaling to match Preview "pix" to template "inches" (24 pixels/inch)
$Inch = 24;
//Create Text Overlay from blank overlay image
$overlay = imagecreatefrompng("Images/Overlay_Blanks/24x36.png");
//Get Stored Text
$SQL="Select * From PreviewText Where ProjectID =".$Info['ProjectID'];
$StoredText = mysql_query($SQL);
while($Text = mysql_fetch_array($StoredText))
{
$SQL="Select * From Texts Where TemplateID = ".$Info['TemplateID']." and TextID = ".$Text['TextID'];
$LayoutValues = mysql_query($SQL);
$Values = mysql_fetch_array($LayoutValues);
//Get Colors
$Color = $Values['Color'];
//Assign Colors
$SQL="Select * From Colors Where Name = '$Color'";
$ColorRGB = mysql_query($SQL);
$RGB = mysql_fetch_array($ColorRGB);
$ShadowColor = imagecolorallocate($overlay, 160, 160, 160);
$TextColor = imagecolorallocate($overlay, $RGB['Red'], $RGB['Green'], $RGB['Blue']);
//Get Positioning Data for Text
$PosLeft = $Values['Left']*$Inch;
$PosHeight = $Values['Height']*$Inch;
$PosBottom = 864-($Values['Bottom']*$Inch);
$PosWidth = $Values['Width']*$Inch;
$Font = $Values['Font'];
$Shadow = $Values['Shadow'];
$FontSize = round($PosHeight);
$box = imagettfbbox ($FontSize, 0, $Font, $Text['Text']);
//Size Text
while ($box[2] >= $PosWidth)
{
$FontSize = $FontSize-1;
$box = imagettfbbox ($FontSize, 0, $Font, $Text['Text']);
}
//Center Text
$PosCenter = round($PosWidth - $box[2])/2-($FontSize/4);
//Set Destination for TextOverlay Image
$TextOverlay = "Images/Text_Overlays/".$Info['ProjectID'].".png";
//Place Text
if ($Shadow == 'Yes')
{
//Shadow
$offset = intval($FontSize/10);
imagettftext($overlay,$FontSize, 0, $PosLeft + $PosCenter + $offset, $PosBottom + $offset, $ShadowColor , $Font , $Text['Text']);
}
//Text
imagettftext($overlay,$FontSize, 0, $PosLeft + $PosCenter, $PosBottom, $TextColor , $Font , $Text['Text']);
}
//Save TextOverlay
imagesavealpha($overlay, true);
imagepng($overlay,$TextOverlay);
//Set Destination for Preview Image
$Time = time();
$Preview = "Images/Previews/".$Info['ProjectID']."_".$Time.".png";
$SQL="Update Projects Set ProjectPreview = '$Preview' Where ClientID = $ClientID and Status = 'Current'";
mysql_query($SQL);
//Create Copy of Blank Project Template for Project Preview
$ProjectPreview = imagecreatefrompng("Images/Masks/".$Info['TemplateName'].".png");
//Create Copy of Photo Overlay
$PhotoOverlay = imagecreatefrompng("Images/Photo_Overlays/".$Info['ProjectID'].".png");
//Create Copy of Text Overlay
$TextOverlay = imagecreatefrompng("Images/Text_Overlays/".$Info['ProjectID'].".png");
//Paste Photo Overlay
imagecopy($PhotoOverlay,$ProjectMask,0,0,0,0,570,864);
//Paste Text Overlay
imagecopy($PhotoOverlay,$TextOverlay,0,0,0,0,570,864);
//Delete Previous Preview
foreach (glob("Images/Previews/".$Info['ProjectID']."*.*") as $filename)
{
unlink ($filename);
}
//Save Preview
imagesavealpha($$PhotoOverlay, true);
imagepng($PhotoOverlay,$Preview);
echo $Preview;
?>
P.S. To see the problem visit
http://www.bragflags.bravehost.com create a flag and then edit text and click on "update".