Drawing a transparent rectangle around a part of an image

MagickWand for PHP is an object-oriented PHP interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning MagickWand for PHP.

Drawing a transparent rectangle around a part of an image

Postby blunt » 2007-03-27T02:53:04+00:00

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
blunt
 

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

Postby anthony » 2007-03-27T16:17:30+00:00

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.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
http://www.imagemagick.org/Usage/
User avatar
anthony
 
Posts: 8684
Joined: 2004-05-31T19:27:03+00:00
Location: Brisbane, Australia

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

Postby blunt » 2007-03-28T01:03:46+00:00

Thanks,

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


Return to MagickWand for PHP

Who is online

Users browsing this forum: No registered users and 1 guest