I have a java appalet that loads on a normal HTML page. The Java appalet allows a user to draw/sign etc. The java appalet then sets the plotted points as a string value.
The actual numbers are plotting points for lines. Each 4 numbers represent (x1, y1) , (x2, y2) for a line.
Example:
10 10 100 10 100 10 100 100 100 100 10 100 10 100 10 10 = A box
so $image would have the above value.
I need to find a method of dynamicly re-creating the image that was drawn in the java appalet using php. I am guessing it will be using the imagesetpixel function within GD in some sort of loop.
I am completly stumped on how to start this, as i havent really worked with the image functions and GD before. If anyone can help it would be greatly appreciated. Any more info needed, please just let me know. Even just enough to get me started would be a great help.
Completly Stumped on how to code this - Images using GD
Moderator: General Moderators
I sat and read the manual and managed to come up with something that does what i need. ITs not saving the files yet, but thats only a quick change.
Here is what I came up with. Its a little messy, but it works
Here is what I came up with. Its a little messy, but it works
Code: Select all
<?
// Write the document header
header("Content-type: image/png");
// Specify the image sizes
$width = 100;
$height = 50;
// Create the image
$im = @imagecreate($width, $height)
or die("Cannot Initialize new GD image stream");
// Set the background Colour
$background_color = imagecolorallocate($im, 0, 0, 0);
// Set the text colour
$text_color = imagecolorallocate($im, 255, 255, 255);
// The TEST string of coardinates
$numbercode = $signature;
// Put the number code variable into the string variable
$string = $numbercode;
// find the number of characters including spaces in the numbercode and write the number to a var
$length = strlen($numbercode);
// loop until the numbercode var is empty and all data is plotted
while ($length > 0) {
$explode = explode(" ", $string, 5);
$length0 = strlen($explode[0]);
$length1 = strlen($explode[1]);
$length2 = strlen($explode[2]);
$length3 = strlen($explode[3]);
$totallength = $length0 + $length1 + $length2 + $length3 + 4;
$num1 = $explode[0];
$num2 = $explode[1];
$num3 = $explode[2];
$num4 = $explode[3];
// Write a line string to the image
Imageline($im,$num1,$num2,$num3,$num4,$text_color);
// removes characters from the original string
$string = substr($string, $totallength);
$length = $length - $totallength;
}
// Output the image to the browser
imagepng($im);
// Destroy the image resources used on the web-server
imagedestroy($im);
?>