Search code examples
phpimagickantialiasing

php imagick annotation antialiasing


I have a webcam and want to add some annotations to image, but antialiasing works strange. I'll try to explain:

I have an image like this: Source image

Then I add semi-transparent rectangle and put text over it:

        //  add background black rectangle
        $draw->setFillColor('black'); 
        $draw->setFillOpacity(0.5);
        $draw->rectangle( 0, 10, $cam['width'], 70 );    // Draw the rectangle 
        //  add lead text
        $draw->setFont('ARIALBD.TTF');
        $draw->setFontSize(14);
        $draw->setFillColor('white');
        $draw->annotation(20, 35, $cam['text']);
        //  add timestamp
        $draw->setFont('ARIAL.TTF');
        $draw->setFontSize(12);
        $draw->setFillColor(new ImagickPixel('#f3ac01'));
        $draw->annotation(20, 50, date("Y-m-d H:i:s"));
        $img->drawImage($draw); 

And get something like this:

Adding text

Huh, but timestamp looks ulgy(look at minutes/seconds). Trying to disable antialiasing:

$draw->setTextAntialias(false);

and now it looks still ugly(look at hours), but now it has sharp edges:

antialiasing turned off

How can I get result with smart antialiasing, like this(I know PS uses own antialiasing, but IMagickDraw deal real bad result):

Want this


Solution

  • For me it looks more like the compression level of the whole image when saved than the antialiasing, have a look at setCompressionQuality, and tweak the compression quality until you avoid the "blurriness" you have in the picture.