Page 1 of 1

Mass Image Creation Script Troubles.

Posted: Mon Jun 16, 2008 8:46 am
by Greenconure
Explanation of where I am:
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)
My Questions:
  • 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 Code
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);
?>

Re: Mass Image Creation Script Troubles.

Posted: Mon Jun 16, 2008 9:11 pm
by Greenconure
Sorry for the bump, but this is extremely important to me.

Re: Mass Image Creation Script Troubles.

Posted: Mon Jun 16, 2008 10:39 pm
by lonelywolf
have you set limit time ?

Code: Select all

set_time_limit(0);

Re: Mass Image Creation Script Troubles.

Posted: Mon Jun 16, 2008 10:50 pm
by John Cartwright
Greenconure wrote:Sorry for the bump, but this is extremely important to me.
As unfortunate as it is, your importance is not ours :) Please keep your bumping to a minimum of 24h. Thanks.

Re: Mass Image Creation Script Troubles.

Posted: Tue Jun 17, 2008 2:28 am
by onion2k
Try unsetting $im after you call imagedestroy(). eg unset($im); ... By the looks of things the first file is being created ok, so there could be some remnant of the previous image messing up the next one. I'm not sure though...

Re: Mass Image Creation Script Troubles.

Posted: Tue Jun 17, 2008 8:10 am
by Greenconure
Jcart wrote:
Greenconure wrote:Sorry for the bump, but this is extremely important to me.
As unfortunate as it is, your importance is not ours :) Please keep your bumping to a minimum of 24h. Thanks.
Sorry about that & it won't happen again. I thought I had read the rules thoroughly but… :|

Re: Mass Image Creation Script Troubles.

Posted: Tue Jun 17, 2008 8:18 am
by Greenconure
onion2k wrote:Try unsetting $im after you call imagedestroy(). eg unset($im); ... By the looks of things the first file is being created ok, so there could be some remnant of the previous image messing up the next one. I'm not sure though...
I tried that… but no cigar. I'm going to see if adding a time limit will help.

Re: Mass Image Creation Script Troubles.

Posted: Tue Jun 17, 2008 8:41 am
by Greenconure
I modified the code so that it only "ran" using two rows in the table..

Code: Select all

$query = 'SELECT * FROM `table` LIMIT 0, 2';
And that produced
  • One good image
  • A "Shortcut" to the other image (It doesn't work)
  • A "Shortcut" to "img5" (Which is very odd, because I don't have a "img5" in my table or even database!

Re: Mass Image Creation Script Troubles.

Posted: Tue Jun 17, 2008 9:28 am
by onion2k
Have you commented out the image creation code and tried echo'ing out the database content to make sure it is what it should be? I really can't see anything wrong with that code.

Re: Mass Image Creation Script Troubles.

Posted: Tue Jun 17, 2008 9:53 am
by Greenconure
onion2k wrote:Have you commented out the image creation code and tried echo'ing out the database content to make sure it is what it should be? I really can't see anything wrong with that code.
It echo's the information perfectly.
What I find odd is that even if I have the script run with two rows, it still creates the "shortcuts" and not images - so I'm pretty sure I'm not running a task that would be too hard for the server.

Re: Mass Image Creation Script Troubles.

Posted: Wed Jun 18, 2008 1:24 pm
by Greenconure
Jcart wrote:
Greenconure wrote:Sorry for the bump, but this is extremely important to me.
As unfortunate as it is, your importance is not ours :) Please keep your bumping to a minimum of 24h. Thanks.
This time, I knew to wait :]