Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Images ’on the fly’
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Images ’on the fly’

 Post Reply Post Reply
Author
Mart View Drop Down
Senior Member
Senior Member
Avatar

Joined: 30 November 2002
Status: Offline
Points: 2304
Post Options Post Options   Thanks (0) Thanks(0)   Quote Mart Quote  Post ReplyReply Direct Link To This Post Topic: Images ’on the fly’
    Posted: 06 May 2003 at 9:14am

Hi, I have a script that creates custom graphics

(using the normal <img> tag),

i.

Is it possible to make this inside of the letters be filled with a colour (I only know how to do the line)

ii.

Is it possible to have a drop shadow..

here is the code I use:

<% @Page Language="VB" %>
    <% @Import Namespace="System.Drawing" %>
    <% @Import Namespace="System.IO" %>
    <% @Import Namespace="System.Drawing.Imaging" %>
    <%
    Response.Expires = 0
    Dim newBitmap as Bitmap '= null
    Dim g as Graphics '= null
    Dim sFont as string
    Dim sFontSize as string
    Dim sPhrase as string
    Dim iFontSize as integer
    Dim sColorBackground as string
    Dim oColorBackground as color
    Dim sFontColorName as string
    dim ofont as color
    Dim oFontColor as color
    Dim oFontCounter as font
    Dim oBitMap as bitmap
    Dim oStream as MemoryStream
    dim oStringSize as SizeF
    Dim iWidth as integer
    Dim iHeight as Integer
    Dim oBitmapOut as bitmap
   
    ' Get the phrase to render
    sPhrase = Request.QueryString.Get("Phrase")
    'if sPhrase = Null then str2Render = "No Phrase specified"
   
    ' What font should we use?
    sFont = Request.QueryString.Get("FontName")
    'if sFont = Null Then sFont = "Lucida Sans Unicode"
   
    ' Which font size?
    iFontSize = 12
    sFontSize = Request.QueryString.Get("FontSize")
    'if NOT (sFontSize = NULL) Then
        iFontSize = convert.toint32(sFontSize)
    'End If
   
    ' How about a different background color
    sColorBackground = Request.QueryString.Get("BackgroundColor")
    oColorBackground = Color.White
    'if NOT (sColorBackground = NULL) then
          oColorBackground = ColorTranslator.FromHTML(sColorBackground)
    'end if
   
    ' Should we change the font color?
    sFontColorName = Request.QueryString.Get("FontColor")
    oFont = Color.Black
    'if NOT (sFontColorName = NULL) Then
        oFont = ColorTranslator.FromHTML(sFontColorName)
    'End If
   
    ' Get measurements of the image based on Font Size
    oFontCounter = new Font(sFont, iFontSize)
    oBitmap = new Bitmap(1,1,PixelFormat.Format32bppARGB)
    g = Graphics.FromImage(oBitmap)
    oStringSize = g.MeasureString(sPhrase, oFontCounter)
    iWidth = cint(oStringSize.Width)
    iHeight = cint(oStringSize.Height)
    g.Dispose()
    oBitmap.Dispose()
   
    ' Create a new image with background color, draw the phrase using font, fontcolor and font size
    oBitmapOut = new Bitmap(iWidth,iHeight,PixelFormat.Format32bppARGB)
    g = Graphics.FromImage(oBitmapOut)
    g.FillRectangle(new SolidBrush(oColorBackground), new Rectangle(0,0,iWidth,iHeight))
    g.DrawString(sPhrase, oFontCounter, new SolidBrush(oFont), 0, 0)
   
    ' Output the image as a PNG into a stream
    oStream = new MemoryStream()
    oBitmapOut.Save(oStream,ImageFormat.PNG)
    ' could be BMP, EMF, GIF, JPEG, PNG, TIFF, WMF
   
    ' Send stream to client
    Response.ClearContent()
    Response.ContentType = "image/PNG"
    Response.BinaryWrite(oStream.ToArray())
    Response.End
   
    ' Clean up
    oFontCounter.Dispose()
    oBitmapOut.Dispose()
    g.Dispose()
    'oStream.Dispose() ' Cant dispose of this -- get an error
    'oStringSize.Dispose() ' Cant dispose of this -- get an error
    'oFont.Dispose()
   
    %>

Thanks, Martin.

Back to Top
MorningZ View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 May 2002
Location: United States
Status: Offline
Points: 1793
Post Options Post Options   Thanks (0) Thanks(0)   Quote MorningZ Quote  Post ReplyReply Direct Link To This Post Posted: 09 May 2003 at 11:31pm

i do drop shadows a sneaky way....

i draw black text offset i pixel in each direction and then put the colored text over the offsets.. resulting in something like this:

if you want the code for it, just lemme know and i'll post it

Contribute to the working anarchy we fondly call the Internet
Back to Top
Mart View Drop Down
Senior Member
Senior Member
Avatar

Joined: 30 November 2002
Status: Offline
Points: 2304
Post Options Post Options   Thanks (0) Thanks(0)   Quote Mart Quote  Post ReplyReply Direct Link To This Post Posted: 10 May 2003 at 2:59pm

Yes could you post the code because I am not sure how to do that...

Thanks, Martin.

Back to Top
MorningZ View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 May 2002
Location: United States
Status: Offline
Points: 1793
Post Options Post Options   Thanks (0) Thanks(0)   Quote MorningZ Quote  Post ReplyReply Direct Link To This Post Posted: 11 May 2003 at 8:13am
Contribute to the working anarchy we fondly call the Internet
Back to Top
Mart View Drop Down
Senior Member
Senior Member
Avatar

Joined: 30 November 2002
Status: Offline
Points: 2304
Post Options Post Options   Thanks (0) Thanks(0)   Quote Mart Quote  Post ReplyReply Direct Link To This Post Posted: 11 May 2003 at 9:27am
Could you strip out the upload and resize bit for me because all I need is text and I can't figure out which bit is which thanks Martin.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.