Results 1 to 7 of 7

Thread: Attach text to Image Via Java script

  1. #1

    Thread Starter
    Hyperactive Member deane034's Avatar
    Join Date
    May 2001
    Location
    Sri Lanka
    Posts
    485

    Question Attach text to Image Via Java script

    hey, i am a real newbie to Web design, i was wondering if it is possible to attach text to image via Java script, if it is possible, where can i find some examples?
    regaurds
    me.life = VB

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    If you mean superimposing text upon an image, such that they become one image, using javascript, the answer is no.

  3. #3

    Thread Starter
    Hyperactive Member deane034's Avatar
    Join Date
    May 2001
    Location
    Sri Lanka
    Posts
    485
    ok.... what are the possible solutions for this... even without Java script...
    me.life = VB

  4. #4
    Hyperactive Member
    Join Date
    May 2000
    Location
    Kalix, Norrbotten, SWEDEN
    Posts
    343
    If you just want text over the image, you could do it with a layer that you place over the image that contains your text.

    /Smirre
    Visual Basic
    C, C++
    Java
    Access
    SQL Server

    MCP, MCSD

  5. #5

    Thread Starter
    Hyperactive Member deane034's Avatar
    Join Date
    May 2001
    Location
    Sri Lanka
    Posts
    485
    well.... i want it to convert into a image file.. for example... i write sometin in a text box,and . and that text shud be in my theimage.gif file...
    me.life = VB

  6. #6
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    this may not be useful, but here is how to do it with asp .net

    Code:
    <%@ Page Language="VB" ContentType="image/jpeg" %>
    <%@ Import Namespace="System" %>
    <%@ Import Namespace="System.Drawing" %>
    <%@ Import Namespace="System.Drawing.Drawing2D" %>
    <%@ Import Namespace="System.Drawing.Imaging" %>
    
    <script language="VB" runat="server">
    
    Sub Page_Load(Sender as Object, E as EventArgs) 
    	Dim rnd As New Random()
    	Dim strText As String
    	' create a font
    	Dim fnt As Font = New Font("Arial", 12, FontStyle.Bold)
    	' Load a bitmap based image from a file
    	Dim newBitmap As Bitmap = New Bitmap(Server.MapPath("back.jpg"))
    	' This line is for creating a blank bitmap.
    	'Dim newBitmap As Bitmap = New Bitmap(400,50,PixelFormat.Format32bppARGB)
    	' Bind the Bitmap to the graphics object
    	Dim g As Graphics = Graphics.FromImage(newBitmap)
            
            ' Get a random number to choose what text to show
    	Select Case rnd.Next(5)
    		Case 1
    			strText = "The place to be!"
    		Case 2
    			strText = "What did you expect this message to say?"
    		Case 3
    			strText = "How about a nice hot cup of STFU!"
    		Case 4
    			strText = "Proving Monkeys CAN fly!"
    		Case Else
    			strText = "D'oh!"
    	End Select	
    	
    	' get the length of the string in pixels
    	Dim tempg As Graphics = Graphics.FromImage(new Bitmap(1,1))
    	Dim StringLength As Integer = tempg.MeasureString(strText,fnt).Width
    	tempg.Dispose
    	
    	g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias
    	g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias
    	
            ' Draw the string to the Graphics object. Subtract the strings pixel length from the 
            ' images width do determine postioning so that the lst character is always along the
            ' right edge of the image. Draw shadow first
            g.DrawString(strText, fnt, New SolidBrush(Color.Black), newBitmap.Width - StringLength, 65)
    	g.DrawString(strText, fnt, New SolidBrush(Color.LightSteelBlue), newBitmap.Width - StringLength - 2, 63)
            
            ' Get an array of ImageEncoders..array item 1 is Jpeg.
            Dim imgCodecs() As ImageCodecInfo  = ImageCodecInfo.GetImageEncoders()
    	
    	' Set quality Parameter for the Jpeg codec
    	Dim imgParams As EncoderParameters = New EncoderParameters(1)
    	Dim imgQuality As EncoderParameter = New EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 80)
    	' Set quality
    	imgParams.Param(0) = imgQuality
    	 
    	' Render BitMap Stream Back To Client
    	newBitmap.Save(Response.OutputStream,imgCodecs(1), imgParams)
    	fnt.Dispose()
    	g.Dispose()
    End Sub
    
    </script>
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  7. #7

    Thread Starter
    Hyperactive Member deane034's Avatar
    Join Date
    May 2001
    Location
    Sri Lanka
    Posts
    485
    thanks man... i dont know.. if i cna use it... wud this thing work with free site that support ASP?
    me.life = VB

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width