0

I have an array in PHP with id and blob image binary data.

$mapImages = $mapImages."['".$row['_URI']."','".$imageRow['VALUE']."],";

When I echo this array into a java script variable:

var mapImages = [<?php echo $mapImages; ?>];

Java script breaks ... Finally I would like to use those ID's to properly place images on google maps.

2
  • What error do you get? Also, instead of building string yourself, you may consider json_encode. Commented Jan 10, 2014 at 7:01
  • It echo's all id's and binary data on on IDE's console (Aptana), in chrome browser i get no output at all, seems like it is doing what it is supposed to do. However is there any way i can parse this php array (id, binary data) into JavaScript safely? Commented Jan 10, 2014 at 7:16

1 Answer 1

1

Got it working using base64 encode in php.

base64_encode($imageRow['VALUE'])

This would prepare binary values for safe echo/print into a javascript variable. Since this is already base64 encoded, we can generate image from it using in following way.

"<img height='200' width='200' src='data:image/jpeg;base64,"+mapImages[valJ][1]+"'/>"

Hope this helps !

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

3 Comments

Is there any browser that does not accept data:image/*;base64,...? This looks very interesting!
Its late but, I tested this on FF and Chrome, it works, can't say the same for IE
If what I read about "Data URLs" is correct and up to date, then IE supports it too. DataURLs seem really convenient!

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.