dynamic image from form

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
jeeep
Forum Commoner
Posts: 57
Joined: Fri Apr 28, 2006 1:43 am

dynamic image from form

Post by jeeep »

G'day,
I have a form where data from a teamspeak server is entered, then a picture is selected and then the form is submitted to a php file that takes the variables from this form and makes a dynamic image. My problem is that this information isnt stored, so when that php file is closed the image doesnt exsist anymore. How do I make it to when the form is submitted, it saves the info into some file where the php file uses this to create an image that is stored as a png? Here is what I have so far:

file1 ts_view.html

Code: Select all

<html>
<form action="ts_view.php" method="post">
TS IP :  <input type="text" name="username" size="20" /><br />
UDP Port:  <input type="text" name="port" size="20" />(if not known contact your TS server provider)<br />
TCP Port:  <input type="text" name="tcp" size="20" />(if not known contact your TS server provider)<br />
Title:  <input type="text" name="title" size="20" /><br />
URL  <input type="text" name="url" size="20" /><p>&nbsp;</p>
 <select name="test[]" multiple="multiple">
 
<option value="/teamspeakimg3.png">Image3</option>
<option value="/teamspeakimg4.png">Image4</option>
<option value="/teamspeakimgb5.png">Image5</option>     
<option value="/teamspeakimgb6.png">Image6</option>
<option value="/teamspeakimgb7.png">Image7</option>
<option value="/teamspeakimgb8.png">Image8</option>
<option value="/teamspeakimgb9.png">Image9</option>
<option value="/teamspeakimgb10.png">Image10</option>
<option value="/teamspeakimgb11.png">Image11</option>

</select> <input type="submit" name="submit" value="Submit" /> </pre> </p>
</form>
</html>
file2 ts_view.php

Code: Select all

<?php
require("cyts.class.php");
$ip = $_POST['username'];
$portnum = $_POST['port'];
$urls = $_POST['url'];
$titler = $_POST['title'];
$tcps = $_POST['tcp'];
$cyts = new cyts;
//Parameters are: IP-Address, TCP-Queryport, UDP-Port
$cyts->connect("$ip", $tcps, $portnum) or die ("Unable to connect to TeamSpeak-server");
header("Content-type: image/png");
$images1 = $_POST['test'];
foreach($images1 as $temp)
{
    $temp;
}     
$bg = $temp;
    $im = @ImageCreateFromPNG($bg);
 
    $width =1;
    $fontsize    = 2; 
    $font  = 2;
    $fonta  = 3;
    $black = imagecolorallocate($im, 255, 255, 255); 
   
$srvinfo = $cyts->info_serverInfo();
$playerlist = $cyts->info_playerNameList( );
$tsuser = $cyts->info_playerList();
$list = $cyts->info_channelList();

$tsusers = $cyts->info_playerList();
$tsserv = $cyts->info_serverInfo();
$time =(($srvinfo["server_uptime"])*(1/60)*(1/60)) ; 
$time = round($time,0);

imagestring($im, 2, 80 , 87,$users, $black);

$love=$time;
$titler  = substr($titler , 0,23)."";
imagestring($im, 6, 10, 10,$titler , $black);
$urls  = substr($urls , 0, 36)."";
imagestring($im, 2, 69, 40,$urls , $black);
imagestring($im, 2, 69, 70,$ip , $black);
$srvinfo["server_welcomemessage"]  = substr($srvinfo["server_welcomemessage"] , 0, 15)."..";
imagestring($im, 2, 69, 100,$srvinfo["server_welcomemessage"]  , $black);




imagestring($im, 2, 348, 74, $srvinfo["server_currentusers"] , $black);
imagestring($im, 2, 345, 95,$srvinfo["server_maxusers"]   , $black);

imagestring($im, 2, 45, 128,$time  , $black);
imagestring($im, 2, 230, 128,$srvinfo["server_currentchannels"]  , $black);
imagestring($im, 2, 120, 128, $srvinfo["server_bwoutlastmin"], $black);

    imagePNG($im);
    ImageDestroy;

?>
Hope this question isnt too complicated. :lol:
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

Use the 2nd argument to specify filename for imagepng (same applies to imagejpeg, image gif etc.)

e.g.

Code: Select all

imagepng($im, '/path/to/images/image.png');
jeeep
Forum Commoner
Posts: 57
Joined: Fri Apr 28, 2006 1:43 am

Post by jeeep »

Well I went back and changed that part several times several different ways and it doesnt seem to be working, I kept getting "This image cannot be displayed because it contains errors". I change the permissions to 777, made sure the image path was correct, but still it didnt create an image. Even went back to the way I had it to make sure everything was ok and sure enough the image showed. Perhaps this has something to do with the html form. But would creating an image produce a dynamic image? Meaning when that problem above gets figured out will this image always show up-to-date stats? I was thinking that something was going to need a timestamp on it :?
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

If you create the image as a file, it does not display the image.

Try something like:

Code: Select all

<?php

$path = '/path/to/images/image.png';

imagepng($im, $path);

readfile($path);

?>
jeeep
Forum Commoner
Posts: 57
Joined: Fri Apr 28, 2006 1:43 am

Post by jeeep »

Still "The image “http://jeejee2.100webspace.net/TS/ts_view.php” cannot be displayed, because it contains errors."

Code: Select all

<?php

require("cyts.class.php");
$ip = $_POST['username'];
$portnum = $_POST['port'];
$urls = $_POST['url'];
$titler = $_POST['title'];
$tcps = $_POST['tcp'];
$cyts = new cyts;
//Parameters are: IP-Address, TCP-Queryport, UDP-Port
$cyts->connect("$ip", $tcps, $portnum) or die ("Unable to connect to TeamSpeak-server");
header("Content-type: image/png");
$images1 = $_POST['test'];
foreach($images1 as $temp)
{
    $temp;
}     
$bg = $temp;
    $im = @ImageCreateFromPNG($bg);
 
    $width =1;
    $fontsize    = 2; 
    $font  = 2;
    $fonta  = 3;
    $black = imagecolorallocate($im, 255, 255, 255); 
   
$srvinfo = $cyts->info_serverInfo();
$playerlist = $cyts->info_playerNameList( );
$tsuser = $cyts->info_playerList();
$list = $cyts->info_channelList();

$tsusers = $cyts->info_playerList();
$tsserv = $cyts->info_serverInfo();
$time =(($srvinfo["server_uptime"])*(1/60)*(1/60)) ; 
$time = round($time,0);

imagestring($im, 2, 80 , 87,$users, $black);

$love=$time;
$titler  = substr($titler , 0,23)."";
imagestring($im, 6, 10, 10,$titler , $black);
$urls  = substr($urls , 0, 36)."";
imagestring($im, 2, 69, 40,$urls , $black);
imagestring($im, 2, 69, 70,$ip , $black);
$srvinfo["server_welcomemessage"]  = substr($srvinfo["server_welcomemessage"] , 0, 15)."..";
imagestring($im, 2, 69, 100,$srvinfo["server_welcomemessage"]  , $black);




imagestring($im, 2, 348, 74, $srvinfo["server_currentusers"] , $black);
imagestring($im, 2, 345, 95,$srvinfo["server_maxusers"]   , $black);

imagestring($im, 2, 45, 128,$time  , $black);
imagestring($im, 2, 230, 128,$srvinfo["server_currentchannels"]  , $black);
imagestring($im, 2, 120, 128, $srvinfo["server_bwoutlastmin"], $black);

  

$path = '/TS/aaa.png';

imagepng($im, $path);

readfile($path);



?>
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

Comment out the imagepng() and readfile() lines, and see if any errors appear on screen (add display_errors(1); and error_reporting(E_ALL); at the top of the page if need be)
jeeep
Forum Commoner
Posts: 57
Joined: Fri Apr 28, 2006 1:43 am

Post by jeeep »

Ok I tried it on a different server and it works perfectly. Although it saves it as an image.png, when someone joins the TS server this image.png becomes obsolete. How do I make this image stay updated?
jeeep
Forum Commoner
Posts: 57
Joined: Fri Apr 28, 2006 1:43 am

Post by jeeep »

Is there a way to stick this into that html file somehow? (Perhaps if I put a <?php and ?> at the bottom with this in it, but will it still get the variables?)

Code: Select all

$fp = fopen("stats","w"); variables ; fwrite ($fp,$str); fclose($fp);
So that this will save the variables created into a file where the php file can pull from it? I think I know all of the subcomponents but I dont know how to stick them together to make them work!
Post Reply