Code:
function draw_image ()
{
global $frm;
global $settings;
$q = 'select
hl_listings.*
from
hl_listings
where
(hl_listings.expiration = 0 || date_added + interval hl_listings.expiration day >= current_date)
and hl_listings.status = 1 and
id = ' . $frm['lid'];
$sth = mysql_query ($q);
$row = mysql_fetch_array ($sth);
if (!$row)
{
header ('Location: ' . $settings['site_logo_url']);
exit ();
}
$Y = 1;
$font_id = 5;
$width = imagefontwidth ($font_id) * strlen ($settings['site_name']) + 20;
if ($width < 120)
{
$width = 120;
}
$height = imagefontheight (5) + 1 + imagefontheight (5) + 1 + imagefontheight (3) + 3;
$font_id = 3;
if ($width < imagefontwidth ($font_id) * strlen ($row['name']))
{
$names = preg_split ('/\\s+/', $row['name']);
$height += imagefontheight ($font_id) * sizeof ($names);
}
else
{
$height += imagefontheight ($font_id);
}
$im = imagecreate ($width, 290);
$colors = array ();
$colors['bg'] = imagecolorallocatehex ($im, '#007F00');
$colors['name_bg'] = imagecolorallocatehex ($im, $settings['image_name_bg_color']);
$colors['text'] = imagecolorallocatehex ($im, $settings['image_text_color']);
$colors['up'] = imagecolorallocatehex ($im, '#ff0000');
$colors['wait'] = imagecolorallocatehex ($im, '#999900');
$colors['problem'] = imagecolorallocatehex ($im, '#990000');
$colors['notvisible'] = imagecolorallocatehex ($im, '#FF0000');
$font_id = 5;
$text = $settings['site_name'];
imagestring ($im, $font_id, center ($text, $font_id, $width), $Y, $text, $colors['text']);
$Y += imagefontheight ($font_id) + 1;
$font_id = 3;
if ($width < imagefontwidth ($font_id) * strlen ($row['name']))
{
$names = preg_split ('/\\s+/', $row['name']);
imagefilledrectangle ($im, 1, $Y, $width - 2, $Y + imagefontheight ($font_id) * sizeof ($names), $colors['name_bg']);
foreach ($names as $name)
{
imagestring ($im, $font_id, center ($name, $font_id, $width), $Y, $name, $colors['text']);
$Y += imagefontheight ($font_id);
}
}
else
{
imagefilledrectangle ($im, 1, $Y, $width - 2, $Y + imagefontheight ($font_id), $colors['name_bg']);
imagestring ($im, $font_id, center ($row['name'], $font_id, $width), $Y, $row['name'], $colors['text']);
$Y += imagefontheight ($font_id);
}
$Y += 1;
$font_id = 5;
if ($row['site_status'] == 1)
{
$statuscolor = $colors['up'];
$text = 'SITE IS UP';
}
if ($row['site_status'] == 2)
{
$statuscolor = $colors['wait'];
$text = 'WAITING';
}
if ($row['site_status'] == 3)
{
$statuscolor = $colors['problem'];
$text = 'PROBLEM';
}
if ($row['site_status'] == 4)
{
$statuscolor = $colors['notvisible'];
$text = 'NOT AVALIBLE';
}
imagestring ($im, $font_id, center ($text, $font_id, $width), $Y, $text, $statuscolor);
$Y += imagefontheight ($font_id) + 1;
$font_id = 3;
$text = date ('d m Y');
imagestring ($im, $font_id, center ($text, $font_id, $width), $Y, $text, $colors['text']);
$Y += imagefontheight ($font_id);
header ('Content-type: image/png');
imagepng ($im);
}
function center ($text, $font_id, $width)
{
$len = imagefontwidth ($font_id) * strlen ($text);
return intval (($width - $len) / 2);
}
function imagecolorallocatehex ($im, $color)
{
$red = 0;
$green = 0;
$blue = 0;
if (eregi ('[#]?([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})', $color, $ret))
{
$red = hexdec ($ret[1]);
$green = hexdec ($ret[2]);
$blue = hexdec ($ret[3]);
}
return imagecolorallocate ($im, $red, $green, $blue);
}