binary image data to Image Object

Discussion in 'JavaScript' started by anidotnet, Dec 23, 2006.

  1. #1
    i have a javascript that receives binary image data and i wanted to show it on the html page.

    how do i use javascript to convert it to an image object?

    Is there any better ways to do this?


    Thanx in Advance
     
    anidotnet, Dec 23, 2006 IP
  2. nocookies

    nocookies Peon

    Messages:
    57
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Can you clarify what do you mean by "binary image data" ?
    Is the image encoded in an acceptable format such as jpeg, gif or png and available through a url from your site that the javascript tries to fetch?
     
    nocookies, Dec 23, 2006 IP
  3. anidotnet

    anidotnet Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thnks for the response.
    I am storing image (Binary Format) in SQL database, which is retreived from the database to display on a html file. i can get the data fromthe database to the html file using javascript.
    how do i convert the binary image data back to image object.

    Thanx
     
    anidotnet, Dec 25, 2006 IP
  4. anidotnet

    anidotnet Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    The image would b Jpeg/gif or any image format.
     
    anidotnet, Dec 25, 2006 IP
  5. nocookies

    nocookies Peon

    Messages:
    57
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    You can create an image object in javascript using:

    var image=document.createElement("img");
    image.src="http://www.yourdomain.com/the_image.php";

    and add it to the body of your document by:

    document.body.appendChild(image);

    You should make sure that the php script (or any other language you may use) sets the response content type correctly to 'image/jpeg' or 'image/gif' in order that it will work on all platforms. For instance, in php, before you output the response, you should call:

    header("Content-Type: image/jpeg");
     
    nocookies, Dec 25, 2006 IP
  6. anidotnet

    anidotnet Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Thanx a lot for the response
     
    anidotnet, Dec 29, 2006 IP