Problem adding a highlight with imagecopymerge

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

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($image, $id, $posx, $posy);

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

  // get color index of existing map pixel

  // highlight the spot on the map
  $rectImage = imagecreatetruecolor($spot[3] - $spot[1], $spot[4] -
  $setpixel = imagesetpixel($image, 0, 0,
imagecolorallocate($rectImage, 0, 0, 0));
  $index = imagecolorat($image, $spot[1], $spot[2] + $offset);
  $rgb = imagecolorsforindex($rectImage, $index);
  $color = imagecolorallocate($rectImage, $rgb["red"], $rgb["green"],

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

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

  // clean up

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.


Site Timeline