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.
I like to have my fonts to look something like those lines next to it.
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
Old new
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.
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.