Re: Changing black to blue (2)
| From: | Hugh Bothwell | Date: | Sun, 31 Mar 2002 16:15:06 +0000 |
| Subject: | Re: Changing black to blue (2) | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-90883@lists.php.net to get a copy of this message | ||
> I have a map of the world with all countries. I have
> 250 maps of the same size as png where only one
> country is black, rest is transp.
> Now I neeed to set this country color to blue or red
> to indicate a special spot.
> I just don't want to save the same map double or tripple.
Good! Makes much more sense.
Call this like
<img src='country.php?cty=germany&col=255,0,0'>
(functions in bold you will have to write yourself)
====== country.php ===========
<?php
Header("Content-type: image/png");
$mapURL = '\images\countrymask\'.MAKESAFE($cty);
// load image
$img = ImageCreateFromPNG($mapURL.$mapname)
or MAKEDEFAULTIMAGE();
// parse new desired color
$newcolor = split(',', $col);
// find black
$oldcolor = ImageColorResolve($img, 0, 0, 0);
// change to new color
ImageColorSet($img, $oldcolor, $newcolor[0], $newcolor[1],
$newcolor[2]);
// ... and return result
ImagePNG($img);
?>
Note that depending on how much this gets used,
it may indeed be better (faster, less computationally
intensive) in the long run to use multiple image
copies, ie country_red.png, country_blu.png etc.