link = @mysql_connect($this->host, $this->user, $this->password); if ($this->link === false) { return $this->raiseError('Database connection error: '.mysql_error()); } if (mysql_select_db($this->database) === false) { return $this->raiseError('Database selection error: '.$this->database); } $result = mysql_query($this->maxQuery); if ($result === false) { return $this->raiseError('Query failed: '.mysql_error()); } $max = mysql_fetch_row($result); $this->maxY = $max[0]; mysql_free_result($result); return true; } /** * Find pixels coords and draw these on the current image * * @param integer $image Number of the image (to be used with $this->height) * @return boolean Success */ function drawPixels($image) { $limit = 0; do { /** Select with limit */ $result = mysql_query(sprintf($this->query, $image * $this->height, ($image + 1) * $this->height - 1).' LIMIT '.$limit.','.$this->limit); if ($result === false) { return $this->raiseError('Query failed: '.mysql_error()); } $count = mysql_num_rows($result); while ($click = mysql_fetch_row($result)) { $x = (int) $click[0]; $y = (int) ($click[1] - $image * $this->height); if ($x < 0 || $x >= $this->width) { continue; } /** Apply a calculus for the step, with increases the speed of rendering : step = 3, then pixel is drawn at x = 2 (center of a 3x3 square) */ $x -= $x % $this->step - $this->startStep; $y -= $y % $this->step - $this->startStep; /** Add 1 to the current color of this pixel (color which represents the sum of clicks on this pixel) */ $color = imagecolorat($this->image, $x, $y) + 1; imagesetpixel($this->image, $x, $y, $color); $this->maxClicks = max($this->maxClicks, $color); if ($image === 0) { /** Looking for the maximum height of click */ $this->maxY = max($y, $this->maxY); } } /** Free resultset */ mysql_free_result($result); $limit += $this->limit; } while ($count === $this->limit); return true; } /** * Do some cleaning or ending tasks (close database, reset array...) */ function finishDrawing() { /** Close connection */ mysql_close($this->link); return true; } }