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 Link to comment https://forums.phpfreaks.com/topic/20617-encoding-images/ 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. Link to comment https://forums.phpfreaks.com/topic/20617-encoding-images/#findComment-91045 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] Link to comment https://forums.phpfreaks.com/topic/20617-encoding-images/#findComment-91058 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] Link to comment https://forums.phpfreaks.com/topic/20617-encoding-images/#findComment-91065 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.