I have this script that replaces black or white color with another color as chosen by the user, works ok however on certain colors (purple background green writing) it leaves a white pixelated border around the letters? I cant figure out what to do? see it here - http://marijasorganicpantry.com.au/imagephp.php
<?php
ob_start();
$txtcolor=$_REQUEST['text1'];
$r1txt=hexdec(substr($txtcolor,0,2));
$g1txt=hexdec(substr($txtcolor,2,2));
$b1txt=hexdec(substr($txtcolor,4,2));
$backcolor=$_REQUEST['back1'];
$r1back=hexdec(substr($backcolor,0,2));
$g1back=hexdec(substr($backcolor,2,2));
$b1back=hexdec(substr($backcolor,4,2));
$imgname="demo_the-crown-prints_work-hard_5x7.jpg";
$im = imagecreatefromjpeg($imgname);
$w = imagesx($im);
$h = imagesy($im);
$gd = imagecreatetruecolor($w,$h);
imagecopyresampled($gd, $im, 0, 0, 0, 0, $w, $h, $w, $h);
imagefilter($gd, IMG_FILTER_COLORIZE,$r1txt,$g1txt,$b1txt);
for($x=0;$x<$w;$x++)
{
for($y=0;$y<$h;$y++)
{
$rgb = imagecolorat($gd, $x, $y);
$r = ($rgb >> 16) & 0xFF;
$g = ($rgb >> 8) & 0xFF;
$b = $rgb & 0xFF;
if ($r==255 and $g==255 and $b==255)
{
$pixelColor=imagecolorallocatealpha($gd,$r1back,$g1back,$b1back,10);
imagesetpixel($gd,$x,$y,$pixelColor);
}
}
}
imagejpeg($gd,NULL,100);
$outputBuffer = ob_get_clean();
$base64 = base64_encode($outputBuffer);
echo '<a id="downloadimage" style="text-decoration:none;" download>
<img id="image2" width=150 height=250 src="data:image/jpeg;base64,'.$base64.'" />
<li style="padding-top:7px;textalign:center;display:block;border-radius:10px;background-color:royaleblue;height:30px;width:100px;">download</li></a>';
?>
</div>