Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/228.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在php中使用imagefilter()使图像清晰_Php_Image_Image Processing_Fonts_Gd - Fatal编程技术网

在php中使用imagefilter()使图像清晰

在php中使用imagefilter()使图像清晰,php,image,image-processing,fonts,gd,Php,Image,Image Processing,Fonts,Gd,是否有可能使用imagefilter()函数使图像更清晰?我使用的是imagettftext(),它为字体添加了抗锯齿,字体看起来有点失焦。我喜欢使我的最终图像有点锐化,这样我就可以减少图像中字符周围的模糊 不同的测试图像 使用的字体 Roboto-Thin.ttf Roboto-Black.ttf 带有浅色字体的图像 我喜欢让我的字体看起来像它旁边的线条 深色字体的图像 带有-$font_color的图像(一些web资源建议将字体颜色值设置为负数,这基本上会关闭抗锯齿功能),但在这

是否有可能使用
imagefilter()
函数使图像更清晰?我使用的是
imagettftext()
,它为字体添加了抗锯齿,字体看起来有点失焦。我喜欢使我的最终图像有点锐化,这样我就可以减少图像中字符周围的模糊

不同的测试图像
  • 使用的字体
    • Roboto-Thin.ttf
    • Roboto-Black.ttf
带有浅色字体的图像 我喜欢让我的字体看起来像它旁边的线条

深色字体的图像

带有-$font_color的图像(一些web资源建议将字体颜色值设置为负数,这基本上会关闭抗锯齿功能),但在这种情况下,字体看起来很难看。(从左到右100已禁用抗锯齿)

GD解决方案

$old = "old.png";
$new = "new.png";

$im = imagecreatefrompng($imgname);
imagetruecolortopalette($im, FALSE, 256);
imagecolorset($im, imagecolorclosest($im, 159, 159, 159), 0, 0, 0);
imagecolorset($im, imagecolorclosest($im, 191, 191, 191), 0, 0, 0);

imagepng($im, $new);
imagedestroy($im);
convert old.png -fuzz 0% -fill rgb(0,0,0) -opaque rgb(159,159,159) new.png
convert new.png -fuzz 0% -fill rgb(0,0,0) -opaque rgb(191,191,191) new.png
图像魔术解决方案

$old = "old.png";
$new = "new.png";

$im = imagecreatefrompng($imgname);
imagetruecolortopalette($im, FALSE, 256);
imagecolorset($im, imagecolorclosest($im, 159, 159, 159), 0, 0, 0);
imagecolorset($im, imagecolorclosest($im, 191, 191, 191), 0, 0, 0);

imagepng($im, $new);
imagedestroy($im);
convert old.png -fuzz 0% -fill rgb(0,0,0) -opaque rgb(159,159,159) new.png
convert new.png -fuzz 0% -fill rgb(0,0,0) -opaque rgb(191,191,191) new.png

他们将输出


GD解决方案

$old = "old.png";
$new = "new.png";

$im = imagecreatefrompng($imgname);
imagetruecolortopalette($im, FALSE, 256);
imagecolorset($im, imagecolorclosest($im, 159, 159, 159), 0, 0, 0);
imagecolorset($im, imagecolorclosest($im, 191, 191, 191), 0, 0, 0);

imagepng($im, $new);
imagedestroy($im);
convert old.png -fuzz 0% -fill rgb(0,0,0) -opaque rgb(159,159,159) new.png
convert new.png -fuzz 0% -fill rgb(0,0,0) -opaque rgb(191,191,191) new.png
图像魔术解决方案

$old = "old.png";
$new = "new.png";

$im = imagecreatefrompng($imgname);
imagetruecolortopalette($im, FALSE, 256);
imagecolorset($im, imagecolorclosest($im, 159, 159, 159), 0, 0, 0);
imagecolorset($im, imagecolorclosest($im, 191, 191, 191), 0, 0, 0);

imagepng($im, $new);
imagedestroy($im);
convert old.png -fuzz 0% -fill rgb(0,0,0) -opaque rgb(159,159,159) new.png
convert new.png -fuzz 0% -fill rgb(0,0,0) -opaque rgb(191,191,191) new.png

他们将输出

imagefilter()中没有这样的过滤器(您确实尝试了
IMG\u filter\u EDGEDETECT
?对于快速转换,它可能会给您带来一些好处)。但您可以尝试使用
图像卷积

imageconvolution($imageResource, array(
    array( -1, -1, -1 ),
    array( -1, 16, -1 ),
    array( -1, -1, -1 ),
), 8, 0);
您可能想了解一下,
imageconvolution似乎存在问题

另一种可能是在应用文本之前调整图像大小,使其(比如)放大200%。然后再次使用大200%的字体应用文本。然后对图像进行下采样。根据字体特征,这将具有减少模糊的效果。使用2的整数幂(200%,400%,…)有助于减少伪影。

在imagefilter()中没有这样的过滤器(您确实尝试过IMG\u filter\u EDGEDETECT
?对于尖锐的转换,它可能会给您带来一些好处)。但您可以尝试使用
图像卷积

imageconvolution($imageResource, array(
    array( -1, -1, -1 ),
    array( -1, 16, -1 ),
    array( -1, -1, -1 ),
), 8, 0);
您可能想了解一下,
imageconvolution似乎存在问题


另一种可能是在应用文本之前调整图像大小,使其(比如)放大200%。然后再次使用大200%的字体应用文本。然后对图像进行下采样。根据字体特征,这将具有减少模糊的效果。使用2的整数幂(200%,400%,…)有助于减少伪影。

您使用的是Roboto字体的两个极端。选择浅色或常规版本,它将变暗而不会太暗


字体渲染器的抗锯齿功能无法使细线的厚度小于一个像素,因此会使它们变暗。

您使用的是Roboto字体的两个极端。选择浅色或常规版本,它将变暗而不会太暗


字体渲染器的抗锯齿功能不能使细线的厚度小于一个像素,因此会使它们变暗。

我认为可以通过使用
IMG\u FILTER\u CONTRAST
实现这一点。因为那样会使黑色变暗。关于它的更多信息,请点击这里,我认为您可以通过使用
IMG\u FILTER\u CONTRAST
实现这一点。因为那样会使黑色变暗。更多信息,请点击这里