0

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

Baba
  • 94,024
  • 28
  • 166
  • 217
TeaCupApp
  • 11,316
  • 18
  • 70
  • 150
  • I think you could achieve that by using `IMG_FILTER_CONTRAST`. Since that would make the black colors darker. For more about it, check here http://php.net/manual/en/function.imagefilter.php – Ignacio Belhot Colistro Oct 25 '12 at 23:36

3 Answers3

3

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.

Community
  • 1
  • 1
LSerni
  • 55,617
  • 10
  • 65
  • 107
2

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);
imagedestroy($im);

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 here enter image description here

                  Old                           new
Baba
  • 94,024
  • 28
  • 166
  • 217
0

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.

Mark Ransom
  • 299,747
  • 42
  • 398
  • 622