Date Image Thing

I want to be trendy, too

For shiggles, I wanted to add a nice little trendy date format to my postings, but everything I found seemed a bit too wordy for me. It always looks like this:

<div class="post-date">
<span class="month">10</span>
<span class="day">04</span>
<span class="year">1977</span>
</div>

This site is dynamically generated, so it wouldn't take too much effort in order to implement such a structure, but I'm stubborn... so here goes

Overprocessed, Nerdy Post Date Image Generation


<%@ Import Namespace="System.Drawing" %>
 <%@ Import Namespace="System.Drawing.Imaging" %>
 <script language="VB" runat="server">
 Sub Page_Load(sender as Object, e as EventArgs)
 dim strDt as string = request.querystring("dt")
 dim strMonth as string = left(MonthName(Month(strDt)),3).ToUpper()
 dim strDay as string = Day(strDt).ToString()
 if strDay.Length=1
 	strDay="0" & strDay
 end if
 dim strYear as string = Year(strDt).ToString()
 
  Dim baseMap as Bitmap = new Bitmap(95, 13)
  '13 cuts it off, which looks cool -- see emersian.com
  Dim myGraphic as Graphics = Graphics.FromImage(baseMap)
  Dim upBrush as SolidBrush = new SolidBrush(Color.black)
  Dim downBrush as SolidBrush = new SolidBrush(Color.steelblue)
  Dim MonthFont as Font = new Font("tahoma", 11,FontStyle.Bold)
  Dim dtFont as Font = new Font("tahoma", 14,FontStyle.Bold)
  myGraphic.FillRectangle(new SolidBrush(Color.white), 0, 0, 100, 25)  
  myGraphic.DrawString(strMonth, MonthFont, upBrush, 0, 0)
  myGraphic.DrawString(strDay, MonthFont, downBrush, 30, 0)
  myGraphic.DrawString(strYear, MonthFont, upBrush, 50, 0)
  myGraphic.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias 
  
  Response.ContentType = "image/gif"
  baseMap.Save(Response.OutputStream, ImageFormat.GIF)

  myGraphic.Dispose()
  baseMap.Dispose()
 End Sub
 </script>
%>

Usage

< img src="dt.aspx?dt=DATE STRING HERE" />

Comments


Leave a Comment

 

 







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 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