
There will be no grey border, that’s just a Wordpress thing…
button.aspx
—————-
<%@ Page Language=”vb” AutoEventWireup=”true” CodeBehind=”button.aspx.vb” Inherits=”dcsui.Dynamicbutton” %>
<%@ OutputCache VaryByParam=”m;t” Duration=”9123123″ %>
<%@ Page Language=”vb” AutoEventWireup=”true” CodeBehind=”button.aspx.vb” Inherits=”dcsui.Dynamicbutton” %><%@ OutputCache VaryByParam=”m;t” Duration=”9123123″ %>
button.aspx.vb
——————–
Partial Public Class Dynamicbutton
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
Dim text As String = Me.Request.QueryString(“t”)
If String.IsNullOrEmpty(text) Then
Throw New ApplicationException(“The text url parameter must be specified”)
End If
Dim sMirror As String = Me.Request.QueryString(“m”)
Dim mirror As Boolean = (Not String.IsNullOrEmpty(sMirror) AndAlso sMirror = “t”)
Dim rightImageWidth As Integer = 10
‘ in pixels
Dim imageHeight As Integer = 42
Dim topPadding As Integer = 11
‘ top and bottom padding in pixels
Dim sidePadding As Integer = 10
‘ side padding in pixels
Dim textBrush As System.Drawing.SolidBrush = New SolidBrush(Color.White)
Dim font As System.Drawing.Font = New Font(“Arial Black”, 11)
‘——– Calculate the text’s width
Dim bitmap As System.Drawing.Bitmap = New Bitmap(300, 300)
Dim graphics__1 As System.Drawing.Graphics = Graphics.FromImage(bitmap)
Dim textSize As System.Drawing.SizeF = graphics__1.MeasureString(text, font)
bitmap.Dispose()
graphics__1.Dispose()
‘——– Create the graphics object
Dim bitmapWidth As Integer = sidePadding * 2 + CInt(textSize.Width)
bitmap = New Bitmap(bitmapWidth, imageHeight)
‘bitmap = new Bitmap(500, 40);
graphics__1 = Graphics.FromImage(bitmap)
‘ Draw the background
Dim leftImage As System.Drawing.Image = System.Drawing.Image.FromFile(Me.Server.MapPath(“~/images/dcs/button-left.png”))
Dim rightImage As System.Drawing.Image = System.Drawing.Image.FromFile(Me.Server.MapPath(“~/images/dcs/button-right.png”))
graphics__1.DrawImage(leftImage, 0, 0, bitmapWidth – rightImageWidth, imageHeight)
graphics__1.DrawImage(rightImage, bitmapWidth – rightImageWidth, 0, rightImageWidth, imageHeight)
‘ These disposes are necessary, otherwise the files get locked
leftImage.Dispose()
rightImage.Dispose()
If mirror Then
bitmap.RotateFlip(RotateFlipType.RotateNoneFlipX)
End If
‘ Draw the text
graphics__1.DrawString(text, font, textBrush, sidePadding, topPadding)
‘——– Serve the Image
Me.Response.ContentType = “image/x-png”
Dim memStream As System.IO.MemoryStream = New System.IO.MemoryStream()
bitmap.Save(memStream, System.Drawing.Imaging.ImageFormat.Png)
memStream.WriteTo(Me.Response.OutputStream)
‘ Some cleanup, not sure if it is all needed
Me.Response.[End]()
memStream.Dispose()
graphics__1.Dispose()
bitmap.Dispose()
End Sub
End Class
———————————————————————————–
Save these two button images to the correct location as specified in the code above (use Photoshop to change the color)