regdude Posted April 20, 2008 Share Posted April 20, 2008 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). Quote Link to comment https://forums.phpfreaks.com/topic/101965-autorun-script/ Share on other sites More sharing options...
jonsjava Posted April 20, 2008 Share Posted April 20, 2008 Need some code to play around with, dude. Quote Link to comment https://forums.phpfreaks.com/topic/101965-autorun-script/#findComment-521824 Share on other sites More sharing options...
regdude Posted April 20, 2008 Author Share Posted April 20, 2008 <?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 Quote Link to comment https://forums.phpfreaks.com/topic/101965-autorun-script/#findComment-521826 Share on other sites More sharing options...
jonsjava Posted April 20, 2008 Share Posted April 20, 2008 <?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* Quote Link to comment https://forums.phpfreaks.com/topic/101965-autorun-script/#findComment-521831 Share on other sites More sharing options...
regdude Posted April 20, 2008 Author Share Posted April 20, 2008 <?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'. Â Quote Link to comment https://forums.phpfreaks.com/topic/101965-autorun-script/#findComment-521838 Share on other sites More sharing options...
jonsjava Posted April 20, 2008 Share Posted April 20, 2008 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); } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/101965-autorun-script/#findComment-521840 Share on other sites More sharing options...
jonsjava Posted April 20, 2008 Share Posted April 20, 2008 Oh, and the little addon script I just noticed you added at the end: it won't work. If you would have posted the full script first, i could have fixed it up. Now, I'm just gonna let someone else do it, because I'm tired. Quote Link to comment https://forums.phpfreaks.com/topic/101965-autorun-script/#findComment-521841 Share on other sites More sharing options...
regdude Posted April 20, 2008 Author Share Posted April 20, 2008 Well ok, thanks for the help anyway. Will wait for help. Quote Link to comment https://forums.phpfreaks.com/topic/101965-autorun-script/#findComment-521845 Share on other sites More sharing options...
regdude Posted April 20, 2008 Author Share Posted April 20, 2008 i fixed my old update script and now that works. Then it comes to the 2nd question. Is it possible to make that script(in this case its a page with name update.php) in a timer to make it run? For example every hour. Â Quote Link to comment https://forums.phpfreaks.com/topic/101965-autorun-script/#findComment-521853 Share on other sites More sharing options...
GingerRobot Posted April 20, 2008 Share Posted April 20, 2008 Using linux? Read up about cronjobs. Using windows? Read up about scheduled tasks. Quote Link to comment https://forums.phpfreaks.com/topic/101965-autorun-script/#findComment-521951 Share on other sites More sharing options...
regdude Posted April 20, 2008 Author Share Posted April 20, 2008 Im using Gentoo Linux. Can that be possible that cron will run that page? Quote Link to comment https://forums.phpfreaks.com/topic/101965-autorun-script/#findComment-521987 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.