Jump to content

Archived

This topic is now archived and is closed to further replies.

sford999

encoding images

Recommended Posts

Hi,

I`m wondering if anyone knows how to or a script/program that will encode images into base64 encoding?


TIA

Share this post


Link to post
Share on other sites
[code]<?php
echo base64_encode(file_get_contents("some_image.png"));
?>[/code]

That should do it.

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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 dots
echo 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]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.