JMagick add some text to image

507 views Asked by At

I've tried to add text to image:

        ImageInfo newImageiInfo=new ImageInfo();

        newImageiInfo.setSize("500x500");
        newImageiInfo.setUnits(ResolutionType.PixelsPerInchResolution);
        newImageiInfo.setColorspace(ColorspaceType.RGBColorspace);

        newImageiInfo.setDepth(8);

        MagickImage destImage = new MagickImage();
        destImage.allocateImage(newImageiInfo);
        destImage.setYResolution(480);
        destImage.setXResolution(640);

        destImage.setBorderColor(PixelPacket.queryColorDatabase("red"));

        DrawInfo aInfo = new DrawInfo(newImageiInfo);
        aInfo.setFill(PixelPacket.queryColorDatabase("yellow"));
        aInfo.setUnderColor(PixelPacket.queryColorDatabase("red"));
        aInfo.setOpacity(100);
        aInfo.setPointsize(36);
        aInfo.setFont("Arial");

        aInfo.setGeometry("+50+50");
        aInfo.setText("Test");

        destImage.annotateImage(aInfo);

        destImage.setFileName("file.png");
        destImage.writeImage(newImageiInfo);

But I have only black quadrat only... Where is my mistake? I saw many examples, but it doesn't work for me. But I can scale and composite images as well - therefore ImageMagick and JMagick is works. Help me, please!

1

There are 1 answers

0
Grigorichev Denis On BEST ANSWER

Reason of my problem is: a fonts was not configured. I tried

composite label:Def -geometry +10+10 source.png target.png

and receive:

composite: delegate library support not built-in '/usr/share/fonts/type1/gsfonts/n019003l.pfb' (Freetype) @ warning/annotate.c/RenderFreetype/1743

Then some googling and Solution for me

I hope it's usefull for somebody....