我有一个黑色徽标,使用以下代码进行着色
/**
* Adds the logo to the image, and colours it if the colour isnt black
*/
public function addLogo($color = 'FFFFFF'){
// Future note: The logo has to be black to have it's colour changed. White logo's don't work.
$logoImage = imagecreatefrompng(APPLICATION_PATH . '/../public_html/images/widget/overlay/JSLogo2.png');
// If a hex is passed, and it's not black, colour the logo.
if($color != null && $color != '000000'){
imagefilter($logoImage, IMG_FILTER_COLORIZE, hexdec('0x' . $color{0} . $color{1}), hexdec('0x' . $color{2} . $color{3}), hexdec('0x' . $color{4} . $color{5}));
}
// Get the offset.
$offset = $this->getPadding() + $this->_circleWidth + (5 * $this->_scaleFactor);
imagecopyresampled(
$this->getImage(),
$logoImage,
$offset,
($this->_scaleFactor * $this->_padding),
0,
0,
$this->_logoWidth,
$this->_logoHeight,
$this->_oriLogoWidth,
$this->_oriLogoHeight
);
imagedestroy($logoImage);
return $this;
}
输出会为图像的大部分颜色着色,但会留下边缘。无论如何我可以改善颜色的覆盖范围,或者这是PHP能够做到的最好的?下面是输出的屏幕截图。任何徽标颜色和背景颜色都会产生相同的效果。