Page 1 of 1

Drawing a transparent rectangle around a part of an image

Posted: 2007-03-27T02:53:04-07:00
by blunt
Hi, I am creating a graph (first time I'm using PHP's MagickWand - serious lack in tutorials online!) and I need to draw a frame around the graph

Image

The code I have used to do this is (snippet):

Code: Select all

<?php
$drawing=NewDrawingWand();
DrawSetStrokeWidth($drawing,0);
DrawSetStrokeLineCap($drawing, MW_RoundCap);
DrawSetStrokeLineJoin($drawing, MW_RoundJoin);
DrawSetFillOpacity($drawing,1);
DrawSetFont($drawing,"verdana.ttf");
DrawSetFontSize($drawing,8);
DrawSetStrokeAlpha($drawing,1);

$pixel = NewPixelWand();

// highlight today
PixelSetColor($pixel, 'grey');
DrawSetFillColor($drawing, $pixel);          
DrawRectangle($drawing, $this->diagramWidth / 2, 0, (($this->diagramWidth / $this->daysToShow) * ($this->daysToShow / 2 + 1)), $this->diagramHeight - 40);

PixelSetColor($pixel, 'black');
DrawSetFillColor($drawing, $pixel);                

for ($i = 1; $i < $this->daysToShow; $i++) {
        $thisDate = getDate($diagramDate);
        $xCoord = ($this->diagramWidth / $this->daysToShow) * $i;

        // draw day mark and day number
        DrawLine($drawing, $xCoord, $this->diagramHeight - 40, $xCoord, 0);                
        DrawAnnotation($drawing, $xCoord - 5, $this->diagramHeight - 29, $thisDate["mday"]);
        
        $diagramDate += $nrSecondsPerDay;
}

// draw middle cross - y axis
DrawLine($drawing, 0, ($this->diagramHeight - 40) / 2, $this->diagramWidth, ($this->diagramHeight - 40) / 2);


?>
How would I draw a transparent rectangle around the line graph (not around the entire image) ?

Also, if anyone can tell me why some of the lines are darker than the others or if I have done anything wrong here please that would be appreciated.

Thanks

Re: Drawing a transparent rectangle around a part of an image

Posted: 2007-03-27T16:17:30-07:00
by anthony
You can NOT draw transparent. It will just draw nothing! You have to erase pixels to transparency, and that requires making sure the image has a matte (alpha) channel, and using an Alpha Composition method.

See IM Examples (command line) and Dst_Out composition
http://www.imagemagick.org/Usage/compose/#dstout

Anything that you can do via the command line should be posible via the wand. Though the wand with its use of separate wands, can probably do more.

Re: Drawing a transparent rectangle around a part of an image

Posted: 2007-03-28T01:03:46-07:00
by blunt
Thanks,

I ended up just drawing 4 lines around it as a border.