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

Text Height, Letter Spacing

Feb 3 at 5:51 PM
Edited Feb 3 at 5:52 PM
  1. There is a way to get height of the text, or should create a new image and get image height?
  2. There is a way to set LetterSpacing of the text?
Imports ImageMagick

public class PageClass

    Inherits System.Web.UI.Page

    sub Page_Load(Src as Object, E As EventArgs)

        Response.ContentType = "image/JPEG"

        ' Read from file.
        Using image As New MagickImage(Server.MapPath("../img.jpg"))

             drawText("50", 200, 413, 284).Draw(image)

            image.Write(Response.OutputStream, MagickFormat.Jpeg)

        End Using

    end sub

    private function drawText(ByVal text As String, ByVal fontSize As Integer, Optional ByVal x As Integer = 0, Optional ByVal y As Integer = 0) As Drawables

        dim d = New Drawables()

        d.Text(x, y + (146), text)

        'd.StrokeColor(New MagickColor(0, Quantum.Max, 0))
        'd.StrokeColor(New MagickColor("yellow"))
        'd.Ellipse(256, 96, 192, 8, 0, 360)

        return d

    end function

end class
Feb 5 at 12:26 PM
You can change the letter spacing of the text with the TextKerning method. The Drawables class has no support for getting the width or height of the text. You can do that on the image class with the FontTypeMetrics method of MagickImage. But you will need to modify the font inside the settings first. I think I might be able to add this to the Drawables also. Will do some experimenting next week.
Mar 15 at 1:49 AM
I am another newbee to Magick.Net. Great job!

I think adding FontTypeMetrics to Drawables is a good idea. I am trying to draw a stamp on the back of a TIFF with centered text.

In the mean time how do you "modify the font inside the settings first"? I am trying to determine the pixel length of lines to center the text. I am working with Arial and Arial Bold at two different fontPointSize;s

I presume an MagickImage object has a default font, fontPointSize and density. I see how to change density. I could not find an example of changing the font or fontPointSize to FontTypeMetrics could work on that font and fontPointSize.

Mar 15 at 10:17 AM
By settings I mean the 'Settings' property of a MagickImage object. Would you mind opening an issue on github to request me to add font type metrics to the Drawables? Have you tried to use text alignment to center your text?