Jump to content

Autorun script


regdude

Recommended Posts

Hi!

I recently made a cool dynamic image script :)

Now the problem is that it doesn't update itself because i made a diferent like dynamic image.

I made something like this: theres a php file(tag.php?id=1) when i run it - it makes a image(/sig/sig_1.png - id is 1).

I was wondering if there is a way to make a script wich will automake these images(Like a global update on all ids)

Better even if there will be a timer(maybe a hour).

Link to comment
https://forums.phpfreaks.com/topic/101965-autorun-script/
Share on other sites

<?php
$id = $_GET['id'];

include "config.php"; 
mysql_connect($server, $db_user, $db_pass); 
$result = mysql_db_query($database, "SELECT * FROM users WHERE id=$id"); 
if (mysql_num_rows($result)) { 
while ($qry = mysql_fetch_array($result)) { 
header("Content-type: image/png");

$image = imagecreatefromjpeg("img/template.jpg");
$font_file = "img/CODE2000.TTF";
$font_size = 10;
$font_angle = 0;
$font_color = imagecolorallocate($image, $red, $green, $blue);
$font_color2 = $font_color;

$file_name = "/to/te/dir/sig/sig_$id.png";

imagettftext($image, $font_size, $font_angle, 5, 11, $font_color, $font_file, "Name: $qry[username]");

imagepng($image, $file_name);
imagedestroy($image);
Readfile($file_name);

}
}

mysql_close();

?>

 

Please say something if you see something that could be done better :)

Link to comment
https://forums.phpfreaks.com/topic/101965-autorun-script/#findComment-521826
Share on other sites

<?php
include "config.php"; 
mysql_connect($server, $db_user, $db_pass); 
$result = mysql_db_query($database, "SELECT * FROM users"); 
if (mysql_num_rows($result)) {
$usernames = array();
$id_array = array();
$old_count = 0;
while ($qry = mysql_fetch_assoc($result)) {
$usernames[$old_count] .= $qry['username'];
$id_array[$old_count] .= $qry['id'];
$old_count++;
}
$count = 0;
foreach ($id_array as $value){
header("Content-type: image/png");
$image = imagecreatefromjpeg("img/template.jpg");
$font_file = "img/CODE2000.TTF";
$font_size = 10;
$font_angle = 0;
$font_color = imagecolorallocate($image, $red, $green, $blue);
$font_color2 = $font_color;

$file_name = "/to/te/dir/sig/sig_$value.png";

imagettftext($image, $font_size, $font_angle, 5, 11, $font_color, $font_file, "Name: {$usernames['$count']}");

imagepng($image, $file_name);
imagedestroy($image);
Readfile($file_name);

}
}
?>

Now, see? If you would have just posted the code first *sigh* *lol*

Link to comment
https://forums.phpfreaks.com/topic/101965-autorun-script/#findComment-521831
Share on other sites

<?php
include "config.php"; 
mysql_connect($server, $db_user, $db_pass); 
$result = mysql_db_query($database, "SELECT * FROM users"); 
if (mysql_num_rows($result)) {
$usernames = array();
$moneys = array();
$kills = array();
$deaths = array();
$id_array = array();
$old_count = 0;
while ($qry = mysql_fetch_assoc($result)) {
$usernames[$old_count] .= $qry['username'];
$moneys[$old_count] .= $qry['money'];
$kills[$old_count] .= $qry['kills'];
$deaths[$old_count] .= $qry['deaths'];
$id_array[$old_count] .= $qry['id'];
$old_count++;
}
$count = 0;
foreach ($id_array as $value){
header("Content-type: image/png");
$image = imagecreatefromjpeg("img/template.jpg");
$font_file = "img/CODE2000.TTF";
$font_size = 10;
$font_angle = 0;
$font_color = imagecolorallocate($image, $red, $green, $blue);
$font_color2 = $font_color;

$file_name = "/to/the/dir/sig/sig_$value.png";

$ratio = ({$kills['$count']}/{$deaths['$count']});
$rg = number_format($ratio, 2);

imagettftext($image, $font_size, $font_angle, 5, 11, $font_color, $font_file, "Name: {$usernames['$count']}");
imagettftext($image, $font_size, $font_angle, 5, 26, $font_color, $font_file, "Money: {$moneys['$count']}$");
imagettftext($image, $font_size, $font_angle, 5, 41, $font_color, $font_file, "Kills: {$kills['$count']}");
imagettftext($image, $font_size, $font_angle, 5, 55, $font_color, $font_file, "Deaths: {$deaths['$count']}");
imagettftext($image, $font_size, $font_angle, 5, 70, $font_color, $font_file, "Ratio: $rg");

$result2 = mysql_db_query($database, "SELECT * FROM bans WHERE username='{$usernames['$count']}'"); 
if (mysql_num_rows($result2)) {
$banned = imagecreatefromgif("img/banned.gif");
imagecopyresampled($image, $banned, 208, 35, 0, 0, 56, 81, 56, 81);
}   

imagepng($image, $file_name);
imagedestroy($image);
Readfile($file_name);

}
}
?>

 

It doesn't seem to work.

What it does is give a invalid image at the end of the script and messup all other images (sig_id.png) there are now no names or other values.

 

Btw, i have over 4000 rows in 'users'.

 

Link to comment
https://forums.phpfreaks.com/topic/101965-autorun-script/#findComment-521838
Share on other sites

you have errors in your code for one, and for two, you modified my code without knowing how it works. Don't blame me for your errors.

Now, with that said, this *MODIFIED* code seems to be clean. I can't guarantee it will do what you want, but syntax-wise, it's clean:

<?php
include "config.php"; 
mysql_connect($server, $db_user, $db_pass); 
$result = mysql_db_query($database, "SELECT * FROM users"); 
if (mysql_num_rows($result)) {
$usernames = array();
$moneys = array();
$kills = array();
$deaths = array();
$id_array = array();
$old_count = 0;
while ($qry = mysql_fetch_assoc($result)) {
$usernames[$old_count] .= $qry['username'];
$moneys[$old_count] .= $qry['money'];
$kills[$old_count] .= $qry['kills'];
$deaths[$old_count] .= $qry['deaths'];
$id_array[$old_count] .= $qry['id'];
$old_count++;
}
$count = 0;
foreach ($id_array as $value){
header("Content-type: image/png");
$image = imagecreatefromjpeg("img/template.jpg");
$font_file = "img/CODE2000.TTF";
$font_size = 10;
$font_angle = 0;
$font_color = imagecolorallocate($image, $red, $green, $blue);
$font_color2 = $font_color;

$file_name = "/to/the/dir/sig/sig_$value.png";

$ratio = $kills[$count]."/".$deaths[$count];
$rg = number_format($ratio, 2);

imagettftext($image, $font_size, $font_angle, 5, 11, $font_color, $font_file, "Name: {$usernames['$count']}");
imagettftext($image, $font_size, $font_angle, 5, 26, $font_color, $font_file, "Money: {$moneys['$count']}$");
imagettftext($image, $font_size, $font_angle, 5, 41, $font_color, $font_file, "Kills: {$kills['$count']}");
imagettftext($image, $font_size, $font_angle, 5, 55, $font_color, $font_file, "Deaths: {$deaths['$count']}");
imagettftext($image, $font_size, $font_angle, 5, 70, $font_color, $font_file, "Ratio: $rg");

$result2 = mysql_db_query($database, "SELECT * FROM bans WHERE username='{$usernames['$count']}'"); 
if (mysql_num_rows($result2)) {
$banned = imagecreatefromgif("img/banned.gif");
imagecopyresampled($image, $banned, 208, 35, 0, 0, 56, 81, 56, 81);
}   

imagepng($image, $file_name);
imagedestroy($image);
Readfile($file_name);

}
}
?>

Link to comment
https://forums.phpfreaks.com/topic/101965-autorun-script/#findComment-521840
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.