Question

I'm writing this text layer on my image using ImageResizer's Watermark plugin. Works fine! But now I want use a specific font. If I specify an existing font on my system, works fine!

My problem occurs because I was to use this custom .TTF font. I'm running locally for the moment, so I installed the fonts in my Windows 7. The font looks like it's correctly installed, when I open up Outlook I can use the font there to style my text.

If I reboot though, the font appears uninstalled. When I try to install it again, Windows says it's already installed.

Eventually I tried unblocking the .ttf file and re-installing, did not help. Since I'm using this through my c# code running in IIS I also tried giving the font file (once inside my Windows/Fonts folder) Full Control for "Network service" user (which my application pool is running under).

I checked in InstalledFontCollection installedFonts = new System.Drawing.Text.InstalledFontCollection();, ran with debugger and tried to find my font, was not in there. Tried to load it directly with PrivateFontCollection, I get a file not found exception.

So... I'm running out of ideas here! What should I be looking for to find out what's the problem? Thanks!

Below is the code I'm running to watermark my image:

var c = Config.Current;

// Name layer
var userNameLayerA = new TextLayer();
userNameLayerA.Text = firstName + " " + lastName;
userNameLayerA.TextColor = System.Drawing.Color.Black;
// userNameLayerA.Font = "Verdana"; // --> Works fine!
userNameLayerA.Font = "Headline Two"; // --> Does not work!
userNameLayerA.FontSize = 16;
userNameLayerA.Style = FontStyle.Bold;
userNameLayerA.Align = ContentAlignment.MiddleCenter;
userNameLayerA.Top = new DistanceUnit(295, DistanceUnit.Units.Pixels);

// Register layer
var wp = c.Plugins.Get<WatermarkPlugin>();
wp.NamedWatermarks["userNameLayerA"] = new Layer[] { userNameLayerA };

// Build image
c.CurrentImageBuilder.Build(posterAEnFilePath, posterAEnDestinationFilePath, new ResizeSettings("watermark=userNameLayerA;"));
Was it helpful?

Solution

If it can't be loaded with PrivateFontCollection.AddFontFile, then it certainly won't be accessible to ImageResizer.

Something is preventing the font from being accessed or loaded. It could be a NTFS permissions issues, or some esoteric .NET security rule. I would focus on loading the font with PrivateFontCollection first - if you succeed at that, it will probably work with ImageResizer.

The fact that the font appears uninstalled when you reboot is very suspicious. Fonts are horribly complex and frequently have bugs or corruption. You might try some other TrueType fonts like Open Sans and see if they behave any differently.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top