www.webdeveloper.com
Results 1 to 7 of 7

Thread: How do i get the imagedata from a loaded img?

Hybrid View

  1. #1
    Join Date
    Dec 2009
    Posts
    4

    How do i get the imagedata from a loaded img?

    How do i get the imagedata from a loaded img?

    if i have:
    <img id='myImage' src='generate_image.php' />

    and then i want to copy the current picture and send it whit ajax.

    Can i do something like:
    var image_data = document.getElementById('myImage').data;

    (I can't use ajax or read the file, as it generate a new picture each time, i need to copy the current one)

  2. #2
    Join Date
    Dec 2005
    Posts
    2,984
    If a new image is generated each time then why don't you rewrite the php script? Add some statement that says if the script is requested via Ajax (I do this by passing a get variable) then return the image resource, otherwise (if the get variable specifying an AJAX call is missing) then save the image to the server.
    I've switched careers...
    I'm NO LONGER a scientist,
    but now a web developer...
    awesome.

  3. #3
    Join Date
    Dec 2009
    Posts
    4

    not my script

    Its not my server, i need it for a greasmonkey script.

    The ajax is doing a OCR on the picture.

  4. #4
    Join Date
    Apr 2006
    Location
    Houston
    Posts
    1,374
    JavaScript can't send the img data, only the src URL (which should be all your server side program should need).

    List of all the IMG tag DOM properties can be found here:
    http://www.w3schools.com/jsref/dom_obj_image.asp

    http://www.w3.org/TR/1999/REC-html40....html#edef-IMG

  5. #5
    Join Date
    Dec 2005
    Posts
    2,984
    Sorry, I misunderstood the question.
    I've switched careers...
    I'm NO LONGER a scientist,
    but now a web developer...
    awesome.

  6. #6
    Join Date
    Jul 2008
    Location
    urbana, il
    Posts
    2,787
    if you are using greasmonkey, you can ajax the image url, load it to a canvas tag, and export the canvas to a dataURI. look up "cross domain greasemonkey" and "canvas tag"...

  7. #7
    Join Date
    Dec 2009
    Posts
    4
    Quote Originally Posted by rnd me View Post
    if you are using greasmonkey, you can ajax the image url, load it to a canvas tag, and export the canvas to a dataURI. look up "cross domain greasemonkey" and "canvas tag"...
    think you missed:
    Quote Originally Posted by Puggan
    I can't use ajax or read the file, as it generate a new picture each time, i need to copy the current one
    But il got a link to some exemple code on canvas on antoher forum.
    http://stackoverflow.com/questions/9...-in-javascript

    Il try that out.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles