I am trying to convert a text to an image. When I see the converted image, the font family is changed. This is my code that works fine on my localhost, but when I deploy the code to the server. The font family family that I specified in the image conversion is gone and is replaced by Arial font. Below is the code:
public async Task<byte[]> ConvertTextToImage(string text)
{
byte[] bytes = null;
using (var stream = new MemoryStream())
{
Bitmap bitmap = new Bitmap(950, 200, PixelFormat.Format64bppArgb);
Graphics graphics = Graphics.FromImage(bitmap);
graphics.Clear(Color.White);
graphics.SmoothingMode = SmoothingMode.AntiAlias;
graphics.TextRenderingHint = TextRenderingHint.AntiAlias;
graphics.DrawString(text, new Font("Journal", 100, FontStyle.Regular), new SolidBrush(Color.FromArgb(0, 0, 255)), new PointF(0.4F, 2.4F));
graphics.Flush();
graphics.Dispose();
bitmap.Save(stream, ImageFormat.Jpeg);
bitmap.Dispose();
bytes = stream.ToArray();
return bytes;
}
}
As you can see that the font family is "Journal", but after deployment, I can see that the image is there, but the font family is Arial. I am not sure how to even troubleshoot this issue on the server because it is working fine on the localhost. I used the System.drawing.common to convert from text to image. font family "Journal" is installed on the server. any help in troubleshooting or why this is occurring only the server will be highly appreciated. I can install the .ttf file in my application, but not sure where to install this font inside the application and how to refer it inside the code.