This project has moved. For the latest updates, please go here.

Generate an image based on character and font

Nov 20, 2013 at 2:30 AM
Trying to have an image with the following property, but there is no pixels in image.
Using image As New MagickImage
    image.Format = MagickFormat.Png

    Dim color As New MagickColor        
    color.R = 0        '    
    color.G = 0        
    color.B = 0
        
    image.FillColor = color    

    Dim colorFont As New MagickColor 
    color.R = 255      
    color.G = 255
    color.B = 255     
  
    image.Label = "text"   
    image.StrokeColor= "colorFont"     

    image.Font = "PMingLiu"   
    image.FontPointsize = 20  

    picLink = "C:\textImage\testingImage.png"
    image.Write(picLink)
        
End Using
Coordinator
Nov 20, 2013 at 10:34 AM
Edited Nov 20, 2013 at 11:02 AM
You should use the drawable classes to draw text on an image:
using (MagickImage image = new MagickImage(Color.Black, 100, 100))
{
  DrawableFont font = new DrawableFont("PMingLiu");
  DrawablePointSize pointSize = new DrawablePointSize(20);
  DrawableStrokeColor strokeColor = new DrawableStrokeColor(Color.White);
  DrawableText text = new DrawableText("YOUR TEXT");
 
  image.Draw(font, pointSize, strokeColor, text);
}
Nov 21, 2013 at 10:07 AM
Thank you so much dlemstra! The picture could be generated with the property you listed. Is it also possible to import a system ttc font to DrawableFont apart from new DrawableFont("PMingLiu"); ?
Coordinator
Nov 21, 2013 at 10:34 AM
Edited Nov 21, 2013 at 10:34 AM
You can specify another font like this: new DrawableFont("Arial"). Or are you using a font that you did not register in windows?
Nov 22, 2013 at 1:41 AM
The font "Batang" is already installed under Fonts in control panel, but somehow still get "Magick: unable to read font `Batang' @ warning/annotate.c/RenderType/871".
Coordinator
Nov 22, 2013 at 6:46 AM
Edited Nov 22, 2013 at 1:08 PM
You can see that fonts that are available using the command line version of ImageMagick. Try the following:
convert -list font
Edit:
You can also experiment with pango: http://www.imagemagick.org/Usage/text/#pango
// UNTESTED!
using (MagickImage image = new MagickImage())
{
  image.Font = "Batang";
  image.FontPointsize = 20;
  image.StrokeColor = Color.White;
  image.Read("pango:您的文字 <b>bold</b>");
 
  image.Write(picLink);
}