0

I'm creating image uploader for my website. I figured out how to upload image from computer and wrote the whole processing script; Now I need to add an option to upload an image from web. My script works fine after the image is converted into 64 bit format:

data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEASABIAAD/2wBDAAMCAgIC

Looks like it is impossible to do anything helpful with image before it is on my server, so I have this script which creates a temporary copy of the image on my host:

$content = file_get_contents("http://cs6045.vk.me/v6045344/43ce/D7BD4GsCmG4.jpg");
file_put_contents("image.png",$content);

So, what I need to do is to take a link "image.png" in JavaScript and transform it to 64 bit format to apply further actions in JavaScript. I can't find a solution anywhere, can someone help?

1
  • 2
    you mean base64 ? right ? Commented Jul 9, 2013 at 11:44

1 Answer 1

1

Please take a look at this thread, where a complete solution to convert an image to base64 is provided. This requires HTML5 tho, so your client needs a relatively up-to-date browser.

There seems tho to be some issues between the browsers, since they process image data differentely. If you want 100% the same Base64 encoding as your PHP-script, I suggest you simply make an AJAX-call to the script, which processes the image. Then it returns the Base64 string.

Sign up to request clarification or add additional context in comments.

2 Comments

im not quite understanding this code, is img a string like "image.png"? If so, I cant make it work
oh, sure it is a new Image element

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.