PDA

View Full Version : Problem with drawing multiple rectangles as png



UD2006
11-28-2011, 08:44 AM
Hello guru's, I try to draw multiple rectangle using numbers from a database in php.
But all I get is an empty imagefield.
The problem is that the numbers from the database are bigger then the actual is going to be, so they need to be smaller.

I used the following code to do this:


<?
$query = $db -> prepare("select alpb_box_id, alpb_style::lvarchar as STYLESHEET from ao_link_page_boxes WHERE alpb_li_id = 755 AND alpb_lngcode = '031' AND alpb_pageno = 1");
$query -> execute();
$result = array();
while($row = $query->fetch(PDO::FETCH_ASSOC)) {
$result[] = $row;
}
$new_styles = array();
$styles_to_collect = array('left', 'top', 'width', 'height', 'type');
foreach($result as $r)
{
$new_entry = array();
foreach($styles_to_collect as $stc)
{
preg_match('/[\s]\s*'.$stc.':\s*([\d]+)/', $r['STYLESHEET'], $matches);
$new_entry[$stc] = $matches[1];
}
if (substr($r['ALPB_BOX_ID'],0,3)== 'IMG') {
$new_entry['type'] = 'purple';
} else {
$new_entry['type'] = 'green';
}
$new_styles[$r['ALPB_BOX_ID']] = $new_entry;
}
$db = null;


$arr = $new_styles;
foreach ($arr as $value) {

$left = $value['left'] / 11;
$top = $value['top'] / 11;
$width = $value['width'] / 11;
$height = $value['height'] / 11;
$color = $value['type'];

$drawArea = ImageCreate(73,103);

$white = ImageColorAllocate ($drawArea, 255, 255, 255);
$green = ImageColorAllocate ($drawArea, 0, 128, 0);
$purple = ImageColorAllocate ($drawArea, 128, 0, 128);

ImageFilledRectangle($drawArea, $left, $top, $width, $height, $color);

}
header("Content-type: image/png");
ImagePNG($drawArea);
?>

The top, left, width, height are css numbers that is used to create the rectangles.

Hope someone can help me with this
Thanks