0
我有这个脚本,用用户选择的另一种颜色替换黑色或白色,但在某些颜色(紫色背景绿色书写)上工作正常,它会在字母周围留下白色像素化边框? 我不知道该怎么办? 看到它在这里 - http://marijasorganicpantry.com.au/imagephp.php在图像上的PHP颜色替换
<?php
ob_start();
\t $txtcolor=$_REQUEST['text1'];
\t $r1txt=hexdec(substr($txtcolor,0,2));
$g1txt=hexdec(substr($txtcolor,2,2));
\t $b1txt=hexdec(substr($txtcolor,4,2));
\t
\t $backcolor=$_REQUEST['back1'];
\t $r1back=hexdec(substr($backcolor,0,2));
$g1back=hexdec(substr($backcolor,2,2));
\t $b1back=hexdec(substr($backcolor,4,2));
\t $imgname="demo_the-crown-prints_work-hard_5x7.jpg";
\t
\t $im = imagecreatefromjpeg($imgname);
\t $w = imagesx($im);
\t $h = imagesy($im);
\t $gd = imagecreatetruecolor($w,$h);
\t imagecopyresampled($gd, $im, 0, 0, 0, 0, $w, $h, $w, $h);
\t imagefilter($gd, IMG_FILTER_COLORIZE,$r1txt,$g1txt,$b1txt);
\t for($x=0;$x<$w;$x++)
\t {
\t \t for($y=0;$y<$h;$y++)
\t \t \t {
\t \t \t \t $rgb = imagecolorat($gd, $x, $y);
\t \t \t \t $r = ($rgb >> 16) & 0xFF;
\t \t \t \t $g = ($rgb >> 8) & 0xFF;
\t \t \t \t $b = $rgb & 0xFF;
\t \t \t \t
\t \t \t \t if ($r==255 and $g==255 and $b==255)
\t \t \t \t { \t
\t \t \t \t $pixelColor=imagecolorallocatealpha($gd,$r1back,$g1back,$b1back,10);
\t \t \t \t imagesetpixel($gd,$x,$y,$pixelColor); \t
\t \t \t \t }
\t \t \t }
\t }
\t
imagejpeg($gd,NULL,100);
$outputBuffer = ob_get_clean();
$base64 = base64_encode($outputBuffer);
echo '<a id="downloadimage" style="text-decoration:none;" download>
\t <img id="image2" width=150 height=250 src="data:image/jpeg;base64,'.$base64.'" />
\t <li style="padding-top:7px;textalign:center;display:block;border-radius:10px;background-color:royaleblue;height:30px;width:100px;">download</li></a>'; \t
?>
感谢那个之间的区别,我已经采取了最灰度的尝试,使图像纯黑和白色但是我仍然有一些灰色斑点的图像,所以他们显示为白色,我怎么可以添加额外的灰色颜色的代码,以便他们也转换?我试过如果($ r == 255和$ g == 255和$ b == 255 || $ r == 212和$ g == 212和$ b == 212 || $ r == 224和$ g == 224和$ b == 224),但它不工作代码有什么问题? – user2530616
如果你想假设原始图像只是白色和黑色,只要尝试做这样的事情如果($ r!== 0 || $ g!== 0 || $ b!== 0)。在你的代码中,你忘记了很多可能的组合;) – Davide
当我放大时,我可以看到很多灰色斑点,所以我想也许如果我可以得到它们的值并将它们全部添加进去,至少可以获得更好的质量并获得摆脱一些景点:)我怎样才能添加更多的阴影代码?我卡住了 – user2530616