By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,011 Members | 1,016 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,011 IT Pros & Developers. It's quick & easy.

Problem adding a highlight with imagecopymerge

P: n/a
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
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.