This project has moved and is read-only. For the latest updates, please go here.

Density not affecting font size

Jul 10, 2015 at 2:48 AM
I am wondering if anyone else has run into this. From what I understand when you set the image density and the font size renders in relation to this (points)

I am creating an online preview of a business card. The preview is supposed to be 171 PPI and am setting the DrawablePointSize to "10".

The image is getting saved at 171 PPI which I want but the font is rendering in size as if the low res preview was 72 PPI. Here is the caption function I am using for each text field:
public void WriteCaption(MagickImage Background, string Txt, double PPI, string fontFamily, double fontSize, string FontColor, int CaptionX, int CaptionY, int CaptionW, int CaptionH, string TextAlign)
        if (!String.IsNullOrEmpty(Txt))
            var bgColor = new MagickColor(Color.Transparent);
            var fillColor = new MagickColor("#000000");

            if (!String.IsNullOrEmpty(FontColor))
                fillColor = new MagickColor(FontColor.Replace("0x", "#"));
            Background.Density = new PointD(PPI, PPI);

            using (MagickImage Caption = new MagickImage(bgColor, CaptionW, CaptionH))
                Caption.Density = new PointD(PPI, PPI);
                Caption.Format = MagickFormat.Png;
                Caption.HasAlpha = true;
                Caption.VirtualPixelMethod = VirtualPixelMethod.Transparent;

                var gravity = new DrawableGravity(Gravity.West);

                if (TextAlign.ToLower() == "center")
                    gravity = new DrawableGravity(Gravity.Center);
                if (TextAlign.ToLower() == "right")
                    gravity = new DrawableGravity(Gravity.East);
                DrawableTextAntialias txtDrawableTextAntialias = new DrawableTextAntialias(true);
                DrawableText txtDrawableText = new DrawableText(0, 0, Txt + " " + fontSize);
                DrawablePointSize txtDrawablePointSize = new DrawablePointSize(fontSize);
                DrawableFont txtDrawableFont = new DrawableFont(fontFamily);
                DrawableFillColor txtDrawableFillColor = new DrawableFillColor(fillColor);

                Caption.Draw(txtDrawableTextAntialias, txtDrawableText, txtDrawablePointSize, txtDrawableFont, txtDrawableFillColor,gravity);
                Background.Composite(Caption,CaptionX, CaptionY, CompositeOperator.Over);


Jul 10, 2015 at 12:22 PM
It seems that the on the command line the density of the image is used when drawing fonts. The Magick++ API does not set the density for drawing when the density of the image is changed. I could fix this in Magick++ but that would mean that any user of Magick.NET will see the text in another size if they also set the Density of the image. At this moment there is no option to set the density for drawing but you could 'fix' it by setting the size to fontsize * PPI/72 (the default density is 72). I will have to talk with the rest of the ImageMagick team to see how we will fix this. I will get back to you when I know more.
Jul 10, 2015 at 4:33 PM
Thanks. Using the "fix" works perfect. I will just stick with that.
Jul 11, 2015 at 5:32 PM
In the next version of Magick.NET ( you can set the density for drawing with the new DrawableDensity class.