Dynamically Generated Image Help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
JohnnyOhhh
Forum Newbie
Posts: 4
Joined: Tue Oct 20, 2009 4:59 pm

Dynamically Generated Image Help

Post by JohnnyOhhh »

Ok, so my previous post was somewhat pointless :-/

I am trying to put together a small web application that will dynamically generate a tag to be printed and put onto an actual physical item which included the name of the product, the price, a description, and the barcode. I want these attributes to be edited via a form filled out by an employee. the barcode php is some pre-fab php code that automatically generates an image based on the user input using a form. since I know exactly what I want as the variables I only need to change the number within the link to have it produce the proper barcode for the item. In addition I am having problems getting the values of my text files to change. I think that my host may have the fopen, function disabled which I have to check on but I could use some help getting around this.

Here is what I am using to try and create the final image

Code: Select all

<?php
header("Content-type: image/png");
$barcode = "barcode.txt";
$barcodenum = trim(file_get_contents($barcode));;
 
$image = imagecreatefrompng("../tag.png");
$image02 = imagecreatefrompng("/barcode/html/image.php?code=ean13&o=2&t=30&r=3&text="$barcodenum"&f1=Arial.ttf&f2=15&a1=&a2=&a3=");
 
$Name = "name.txt";
$ProductName = trim(file_get_contents($Name));;
$Price = "price.txt";
$ProductPrice = trim(file_get_contents($Price));;
$Desc = "desc.txt";
$ProductDesc01 = trim(file_get_contents($Desc));;
 
//imagecolorallocate($image, R, G, B) in HEX values
$font_black = imagecolorallocate($image, 2, 1, 8);
$font_red = imagecolorallocate($image, 205, 68, 75);
 
//($image, fontsize, rightindent, downindent, data, txtcolour)
imagestring($image, 10.75, 80, 140, $ProductName, $font_black);
imagestring($image, 20, 80, 225, $ProductPrice, $font_red);
imagestring($image, 8, 80, 300, $ProductDesc01, $font_black);
imagestring($image, 0, 143, 690, $image02); 
 
imagepng($image);
imagedestroy($image);
 
?>
and here is the code for the php that would have the form and write to the text files.

Code: Select all

<?php
 
 $name = "/txt/name.txt";
 $file01 = fopen($name, "w")or die("can't open name.txt");
 if($_POST['name']) fwrite($file01, $_POST['name']);
 fclose($file01);
  
 $price = "/txt/price.txt";
 $file02 = fopen($price, "w")or die("can't open price.txt");
 if($_POST['price']) fwrite($file02, $_POST['price']);
 fclose($file02);
  
 $desc = "/txt/desc.txt";
 $file03 = fopen($desc, "w")or die("can't open desc.txt");
 if($_POST['desc']) fwrite($file03, $_POST['desc']);
 fclose($file03);
  
 $barcode = "/txt/barcode.txt";
 $file04 = fopen($barcode, "w")or die("can't open barcode.txt");
 if($_POST['barcode']) fwrite($file04, $_POST['barcode']);
 fclose($file04);
 ?>
  
  
 <form action="<?=$PHP_SELF?>" method="post">
   <p>Name:
     <input type="text" name="name"/>
   </p>
 <p>Price:
     <input type="text" name="price"/>
   </p>
 <p>Description:
     <input type="text" name="desc"/>
   </p>
 <p>Barcode :
     <input type="text" name="barcode"/>
   </p>
   <p>
     <input type="submit"/>
   </p>
 </form>
In addition, I would love to know how one might be able to combine these two pages into one page where the final image would be displayed without reloading the page.

any help with this is much appreciated.
- Johnny
Post Reply