470,849 Members | 1,081 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,849 developers. It's quick & easy.

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($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.

Jul 17 '05 #1
0 1641

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Ben | last post: by
12 posts views Thread by Joel Byrd | last post: by
5 posts views Thread by helraizer1 | last post: by
3 posts views Thread by helraizer1 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.