Mass Image Creation Script Troubles.
Posted: Mon Jun 16, 2008 8:46 am
Explanation of where I am:
The four asterisks found throughout the script ("****") symbolize a value or variable that I took out for my own security.
My Questions:I have written a script that I hoped would accomplish the task of making a large amount (a little more than 700) individual .pngs from a database. The database has four fields, the name, the "r" value, the "g" value, and the "b" blue value. When I run the script with a test table that is identical in setup to the master table with the 700 rows except that it has only 1 row, it works perfectly. When I run the script with the large table, it creates lots of files with the correct names, that aren't images. They appear to be shortcuts of some kind.
(See the attached image to for a screenshot of the files this script creates)
The Code
- Obviously I need some help, but besides the "Halp meh!" cry, I was wondering...
- Am I trying to perform a task that is too demanding for the server?!
- Is there a better way of doing this?
The four asterisks found throughout the script ("****") symbolize a value or variable that I took out for my own security.
Code: Select all
<?php
$host = '****';
$user = '****';
$pass = '****';
$db = '****';
$link = mysql_connect($host, $user, $pass)
or die('Could not connect: ' . mysql_error());
mysql_select_db($db) or die('Could not select database');
$query = 'SELECT * FROM **** ';
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
while ($row = mysql_fetch_assoc($result)) {
$string = $row['name'];
$saveName = $row['name'];
$r = $row['r'];
$g = $row['g'];
$b = $row['b'];
$im = imagecreate(180,36);
$color = imagecolorallocate($im, $r, $g, $b);
$black = imagecolorallocate($im, 0, 0, 0);
$white = imagecolorallocate($im, 255, 255, 255);
$name = $row['name'];
$fName = $name . ".png";
imagefilledrectangle($im,0,0,180,36, $white); //BG
imagefilledrectangle($im,1,1,118,34, $black); //Rectangle - Border
imagefilledrectangle($im,2,2,117,33, $color); //Rectangle - Fill
imagestring($im,5,122,8,$name,$black); //Text
imagepng($im, $fName);
imagedestroy($im);
}
mysql_free_result($result);
mysql_close($link);
?>