Problem adding a highlight with imagecopymerge

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Doug Farrell

    Problem adding a highlight with imagecopymerge

    Hi all,

    I'm trying to use the PHP GD functions to make graphical changes to
    image files. In particular I'm trying to add a 'highlight' rectangle
    to an image. So far everything I've tried doesn't work as I'd expect.
    The best I've got is to make a copy of the rectangle and
    imagecopymerge( ) it back onto the original with a 'pct' value. This
    creates a visible region, but it isn't highlighted, it's always
    darker. Here is my code for this:

    function highlightSpot($ image, $id, $posx, $posy) {
    global $spots;
    global $offset;

    // get coords of the box to highlight based on $id
    $box = spotLegend($ima ge, $id, $posx, $posy);

    // get the spot information
    $spot = $spots[$id];

    // get color index of existing map pixel

    // highlight the spot on the map
    $rectImage = imagecreatetrue color($spot[3] - $spot[1], $spot[4] -
    $spot[2]);
    $setpixel = imagesetpixel($ image, 0, 0,
    imagecoloralloc ate($rectImage, 0, 0, 0));
    $index = imagecolorat($i mage, $spot[1], $spot[2] + $offset);
    $rgb = imagecolorsfori ndex($rectImage , $index);
    $color = imagecoloralloc ate($rectImage, $rgb["red"], $rgb["green"],
    $rgb["blue"]);

    // copy section of image to new image
    imagecopy($rect Image, $image, 0, 0, $spot[1], $spot[2] + $offset,
    imageSX($rectIm age), imageSY($rectIm age));

    // merge highlight onto map
    imagecopymerge( $image, $rectImage, $spot[1], $spot[2] + $offset, 0,
    0, imageSX($rectIm age), imageSY($rectIm age), 80);
    imagerectangle( $image, $spot[1], $spot[2] + $offset, $spot[3],
    $spot[4] + $offset, imagecoloralloc ate($image, 0, 0, 0));

    // clean up
    imagedestroy($r ectImage);
    }

    What I'd really like is to create a highlighted rectangle in yellow,
    like someone drew on the image with a 'highlighter'. Any help would be
    greatly appreciated.

    Thanks,
    Doug
Working...