GDI+ Font Embedding
The Code: h1.aspx
<%@ Page EnableSessionState="false" Trace=True Language="vb" debug="true" validateRequest=false %> <%@ Import Namespace="System.Drawing" %> <%@ Import Namespace="System.Drawing.Imaging" %> <%@ Import namespace="System.Drawing.Drawing2D" %> <%@ Import namespace="System.Drawing.Text" %> <script language="VB" runat="server"> Sub Page_Load(sender as Object, e as EventArgs) dim myString as String myString = request.querystring("h1") Dim baseMap as Bitmap = new Bitmap(600, 50) Dim myGraphic as Graphics = Graphics.FromImage(baseMap) Dim upBrush as SolidBrush = new SolidBrush(Color.FromArgb(0,0,0)) Dim backBrush as SolidBrush = new SolidBrush(Color.FromArgb(255,255,255)) Dim familyNameAndStyle As String Dim FontCollection As New PrivateFontCollection() FontCollection.AddFontFile(Server.MapPath("TYPEWRIT.TTF")) Dim thisFont As FontFamily thisFont = FontCollection.Families(0) Dim fontTitle As New Font(thisFont, 18) 'or use a system font 'Dim fontTitle as Font = new Font("tahoma", 16) familyNameAndStyle = thisFont.Name myGraphic.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit myGraphic.SmoothingMode = SmoothingMode.Antialias ' antialias objects myGraphic.FillRectangle(backBrush, 0, 0, 600, 50) myGraphic.DrawString(myString, fontTitle, upBrush, 5, 5) Response.ContentType = "image/jpeg" baseMap.Save(Response.OutputStream, ImageFormat.JPEG) myGraphic.Dispose() baseMap.Dispose() End Sub </script>
Usage
<img src="h1.aspx?h1=Hello World" />
Example
Comments
Leave a Comment
Name:
URL:
Comments:
Posts
Latest
Advice (5)
API (2)
ASP.NET (10)
Blogging (2)
Browsers (5)
Classic ASP (1)
Design (1)
Ecommerce (3)
GDI+ (7)
Handy Stuff (4)
IIS (1)
Misc (7)
Money (8)
Opinion (6)
Side Projects (1)
Swish (12)
VBS (3)
Stores
Books
Software
Video Games
Plasma TVs
LCD TVs
DVD Players
Tivo & DVR
HDTVs
MP3 Players
Camcorders
Cameras
Cell Phones
Desktops
Laptops
USB Flash Drives
Hard Drives
LATEST POSTS
PostBackUrl Equals Change the Friggin' Form Action
.
Curse you DBNull and/or Is Nothing!
.
Career Developers are Shitbags
they are.
Consolas Makes Me Geek-ier
MS Consolas Font Abuse
Things I Read Today and You Should Too
Whilst searching for solutions I happened upon...
ADS
MOST POPULAR
Multiple IEs in Windows
Date Image Thing
Firefox Vs. The World
Who Is Xperya?
ActionScript Form Fields
Quick Watermark
IE 7 beta 2 standalone
IP Address Tool
Chicago Web Design
Free Text Messaging