Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Please help this problem is preventing site completion!
Old 10-01-2008, 06:07 PM Please help this problem is preventing site completion!
Sleeping Troll's Avatar
Ultra Talker

Posts: 351
Name: Butch Begy
Trades: 0
I have written a site that is for designing custom vinyl banners it allows client to provide a photo and/or Text for the banner, It creates 3 gd images 1 for basic template, 1 for text and 1 for photo. the text and photo images have alpha transparency and all 3 are saved as .png. The text and photo images are copied to the template image to produce a preview of the banner. 1 example is called "Happy birthday" it has both text and photo and it works fine. The other is called Welcome it contains only text and the problem is there its preview shows only the basic template and does not show the text! The code below is for the text update and the photo update, in that order. I can view the images on the server and they are just fine, but it would seem that the "overlays for text and photo are not being copied to template in the case of "Welcome" banner, however I get no errors thrown. please visit site at http://trollnest.com/bragflags/default.php Try Happy birthday(working properly) then try Welcome (not updating preview). IM me if you think you can help, butchtroll@yahoo.com.

PHP Code:
<?php
$conn 
mysql_connect("p50mysql109.secureserver.net","Brag_Flags","ButchTroll01"); 
mysql_select_db("Brag_Flags",$conn);
$ClientID $_COOKIE["Brag_Flag_user"];
$TextID $_GET["TextID"];
$Text $_GET["Text"];
$SQL="Select * From Projects where ClientID = $ClientID and Status = 'Current'";
$ProjectInfo mysql_query($SQL);
$Info mysql_fetch_array($ProjectInfo);
$SQL="Update PreviewText Set Text = '$Text' Where ProjectID =".$Info['ProjectID']." and TextID = $TextID";
mysql_query($SQL);
//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
$Inch 24;
//Create Text Overlay
$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($overlay160160160);
  
$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 ($FontSize0$Font$Text['Text']);
 
  
//Size Text
  
while ($box[2] >= $PosWidth)
   {
    
$FontSize $FontSize-1;
    
$box imagettfbbox ($FontSize0$Font$Text['Text']);
   }
 
  
//Center Text
  
$PosCenter round($PosWidth $box[2])/2;
 
//Set Destination for OverlayText Image 
$TextOverlay "Images/Text_Overlays/".$Info['ProjectID'].".png";
  
//Place Text
  
if ($Shadow == 'Yes')
   {
    
//Shadow
    
$offset intval($FontSize/10);
    
imagettftext($overlay,$FontSize0$PosLeft $PosCenter $offset$PosBottom $offset$ShadowColor $Font $Text['Text']);
   }
  
//Text
  
imagettftext($overlay,$FontSize0$PosLeft $PosCenter$PosBottom$TextColor $Font $Text['Text']);
}
//Save TextOverlay
imagesavealpha($overlaytrue);
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/Project_Templates/".$Info['ProjectID'].".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($ProjectPreview,$PhotoOverlay,0,0,0,0,570,864);
//Paste Text Overlay 
imagecopy($ProjectPreview,$TextOverlay,0,0,0,0,570,864);
//Delete Previous Preview
foreach (glob("Images/Previews/$Info[0]*.*") as $filename)
 {
  
unlink ($filename);
 }
 
//Save Preview
imagesavealpha($ProjectPreviewtrue);
imagepng($ProjectPreview,$preview);
echo 
$preview;
?>
PHP Code:
<?php
$conn 
mysql_connect("p50mysql109.secureserver.net","Brag_Flags","ButchTroll01"); 
mysql_select_db("Brag_Flags",$conn);
$ClientID $_COOKIE["Brag_Flag_user"];
$SQL="Select * From Projects Where ClientID = $ClientID and Status = 'Current'";
$ProjectInfo mysql_query($SQL);
$Info mysql_fetch_array($ProjectInfo);
//Set Source of Uploaded Project Photo
$image $Info['ProjectPhoto'];
//Create Copy of Original Uploaded Client Photo
$org_img imagecreatefromjpeg($image);
//Get Dimensions of Uploaded Client Photo
$imsize getimagesize($image);
//Scaling to match Cropper
$Factor $imsize[0]/300;
//Scaled Dimensions of Crop
$CropTop=$_GET["Top"]*$Factor;
$CropLeft=$_GET["Left"]*$Factor;
$CropHeight=$_GET["Height"]*$Factor;
$CropWidth=$_GET["Width"]*$Factor;
//Set Destination for Cropped Image
$cropimage "Images/Cropped_Images/".$Info['ProjectID'].".jpg";
//Create Container for Cropped Image
$img imagecreatetruecolor($CropWidth,$CropHeight);
 
//Create Cropped Image
imagecopy($img,$org_img00,$CropLeft,$CropTop$CropWidth$CropHeight);
//Save Cropped Image
imagejpeg($img,$cropimage);
/****************************** Cropping Done Start Create Overlay for Preview ***************************/
//Scaling to match Preview
$Inch 24;
//Get Positioning Data for Photo
$SQL="Select * From Photos Where TemplateID = ".$Info['TemplateID'];
$PositionData mysql_query($SQL);
$Data mysql_fetch_array($PositionData);
$PosLeft $Data[2]*$Inch;
$PosWidth $Data[4]*$Inch;
$PosHeight $Data[5]*$Inch;
$PosTop 864-($Data[3]*$Inch)-$PosHeight;
//Set Destination for OverlayPhoto Image
$PhotoOverlay ="Images/Photo_Overlays/".$Info['ProjectID'].".png";
//Create Photo Overlay
$overlay imagecreatefrompng("Images/Overlay_Blanks/24x36.png");
//Place Photo
imagecopyresized($overlay$img$PosLeft$PosTop00$PosWidth$PosHeight$CropWidth$CropHeight);
//Save PhotoOverlay
imagesavealpha($overlaytrue);
imagepng($overlay,$PhotoOverlay);
//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 Project Template for Project Preview
$ProjectPreview imagecreatefrompng("Images/Project_Templates/".$Info['ProjectID'].".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 Text Overlay 
imagecopy($ProjectPreview,$TextOverlay,0,0,0,0,570,864);
//Paste Photo Overlay
imagecopy($ProjectPreview,$PhotoOverlay,0,0,0,0,570,864);
//Delete Previous Preview
foreach (glob("Images/Previews/$Info[0]*.*") as $filename)
 {
  
unlink ($filename);
 }
 
//Save Preview
imagesavealpha($ProjectPreviewtrue);
imagepng($ProjectPreview,$preview);
echo 
$preview;
?>
Notice that the last part of the 2 scripts is identical, this is where the "overlays" are applied to the Template image. in the case of the Welcome banner the only thing different is that it contains no photo so the photo update script is never called but the photo overlay (which is a blank transparency) is applied in the text update script and vice versa. This is because the preview is created fresh each time a change is made and it is saved with a new filename (timestamp) so that client does not display cached image.

The images are being created properly, I can eyeball them, however the preview has no "overlays" but the script does not generate and error!

Sleeping Troll is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Reply     « Reply to Please help this problem is preventing site completion!
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.97518 seconds with 12 queries