sford999 Posted September 13, 2006 Share Posted September 13, 2006 Hi,I`m wondering if anyone knows how to or a script/program that will encode images into base64 encoding?TIA Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted September 13, 2006 Share Posted September 13, 2006 [code]<?phpecho base64_encode(file_get_contents("some_image.png"));?>[/code]That should do it. Quote Link to comment Share on other sites More sharing options...
sford999 Posted September 13, 2006 Author Share Posted September 13, 2006 Excellent, thanks.How could I reverse that?Meaning if I include it into a script, how would I use the base64?Something like:[code]<?php$string = "encoded string";$image = eval(base64_decode($string));echo "<img src=\"$image\">";?>[/code] Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted September 13, 2006 Share Posted September 13, 2006 To reverse it just:image.php:[code]<?php$string = "bla bla encoded image bla bla";header("Content-type: ..."); // write the mime-type instead of the dotsecho base64_decode($string);?>[/code]other_file.html:[code]...<img src='image.php' alt='image' />...[/code]Or you may do it like this if you want it in one file:some_file.php: [code]<?php$string = "bla bla encoded image bla bla";if(isset($_GET['image'])){ header("Content-type: ..."); // write the mime-type instead of the dots echo base64_decode($string); die();}echo "<img src='some_file.php?image' alt='image' />";?>[/code] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.