2012-10-25 23:26



Is there any possibilities to make image more sharp using imagefilter() function? I am using imagettftext() which adds Anti-aliasing to fonts and the fonts looks bit de-focused. I like to make my final image bit sharpen so that I can reduce the blur around the char's in my image.

Different Test Images

  • Font used
    • Roboto-Thin.ttf
    • Roboto-Black.ttf

Image with light fonts

I like to have my fonts to look something like those lines next to it.

enter image description here

Image with dark fonts

enter image description here

Image with -$font_color (Some web resources suggested to make font colour value to negative which basically turns off the anti-aliasing) But in this case the fonts looks ugly. (Left-To-Right 100 is with turned off anti-aliasing)

enter image description here

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答


  • douke1954 douke1954 9年前

    GD Solution

    $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);

    Image Magic Solution

    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

    They would output

    enter image description hereenter image description here

                      Old                           new
    点赞 评论 复制链接分享
  • doutenglou6588 doutenglou6588 9年前

    You're using the two extremes of the Roboto font. Pick the light or Regular version and it will be dark without being too dark.

    The anti-aliasing function of the font renderer can't make the thin lines less than one pixel thick, so it makes them dim instead.

    点赞 评论 复制链接分享
  • dongpan1416 dongpan1416 9年前

    There is no such filter in imagefilter() (you did try IMG_FILTER_EDGEDETECT? For sharp transitions maybe it can get you something). But you can try and use imageconvolution instead:

    imageconvolution($imageResource, array(
        array( -1, -1, -1 ),
        array( -1, 16, -1 ),
        array( -1, -1, -1 ),
    ), 8, 0);

    You may want to look at PHP imageconvolution() leaves black dot in the upper left corner , there appeared to be an issue with imageconvolution

    Another possibility is to resize the image before applying text, making it (say) 200% larger. Then apply the text using a font again 200% larger. Then downsample the image. Depending on font characteristics, this will have the effect of reducing the blur. Using integer powers of 2 (200%, 400%, ...) helps reducing artifacts.

    点赞 评论 复制链接分享