<p>I am building an open search add-on for Firefox/IE and the image needs to be Base64 Encoded so how can I base 64 encode the favicon I have?</p>

<p>I am only familiar with PHP</p>

[{'answer_id': 35881, 'author': 'OysterD', 'author_id': 2638, 'author_profile': 'https://Stackoverflow.com/users/2638', 'pm_score': 0, 'selected': False, 'text': '<p>Google led me to <a href="http://fr.php.net/base64_encode" rel="nofollow noreferrer">this</a> solution (base64_encode). Hope this helps!</p>\n'}, {'answer_id': 35891, 'author': 'Ross', 'author_id': 2025, 'author_profile': 'https://Stackoverflow.com/users/2025', 'pm_score': 7, 'selected': True, 'text': '<p>As far as I remember there is an xml element for the image data. You can use this <a href="http://www.motobit.com/util/base64-decoder-encoder.asp" rel="noreferrer">website</a> to encode a file (use the upload field). Then just copy and paste the data to the XML element.</p>\n\n<p>You could also use PHP to do this like so:</p>\n\n<pre><code> &lt;?php\n        $im = file_get_contents(\'filename.gif\');\n        $imdata = base64_encode($im);      \n?&gt; \n</code></pre>\n\n<p>Use <a href="http://developer.mozilla.org/en/Creating_OpenSearch_plugins_for_Firefox" rel="noreferrer">Mozilla\'s guide</a> for help on creating OpenSearch plugins. For example, the icon element is used like this:</p>\n\n<pre><code>&lt;img width="16" height="16"&gt;data:image/x-icon;base64,imageData&lt;/&gt;\n</code></pre>\n\n<p>Where <code>imageData</code> is your base64 data.</p>\n'}, {'answer_id': 318624, 'author': 'dlamblin', 'author_id': 459, 'author_profile': 'https://Stackoverflow.com/users/459', 'pm_score': 3, 'selected': False, 'text': '<p>My synopsis of <a href="http://www.ietf.org/rfc/rfc2397.txt" rel="noreferrer">rfc2397</a> is:</p>\n\n<p>Once you\'ve got your base64 encoded image data put it inside the &lt;Image>&lt;/Image> tags prefixed with "<code>data:{mimetype};base64,</code>" this is similar to the prefixing done in the parenthesis of <code>url()</code> definition in CSS or in the quoted value of the <code>src</code> attribute of the <code>img</code> tag in [X]HTML. You can test the data url in firefox by putting the <code>data:image/...</code> line into the URL field and pressing enter, it should show your image.</p>\n\n<p>For actually encoding I think we need to go over all your options, not just PHP,\nbecause there\'s so many ways to base64 encode something.</p>\n\n<ol>\n<li>Use the <code>base64</code> command line tool. It\'s part of the GNU coreutils (v6+) and pretty much default in any <a href="http://cygwin.org" rel="noreferrer">Cygwin</a>, <a href="http://debian.org" rel="noreferrer">L</a><a href="http://ubuntu.com" rel="noreferrer">i</a><a href="http://opensuse.org/" rel="noreferrer">n</a><a href="http://gentoo.org" rel="noreferrer">u</a><a href="http://linux.org" rel="noreferrer">x</a>, <a href="http://gnuwin32.sf.net" rel="noreferrer">GnuWin32</a> install, but not the BSDs I tried. Issue: <code>$ base64 imagefile.ico &gt; imagefile.base64.txt</code></li>\n<li>Use a tool that features the option to convert to base64, like <a href="http://notepad-plus.sf.net" rel="noreferrer">Notepad++</a> which has the feature under plugins->MIME tools->base64 Encode</li>\n<li>Email yourself the file and view the raw email contents, copy and paste.</li>\n<li>Use a <a href="http://makcoder.sourceforge.net/demo/base64.php" rel="noreferrer">web</a> <a href="http://www.motobit.com/util/base64-decoder-encoder.asp" rel="noreferrer">form</a>.</li>\n</ol>\n\n<p>A note on mime-types:\nI would prefer you use one of <code>image/png</code> <code>image/jpeg</code> or <code>image/gif</code> as I <a href="http://www.iana.org/assignments/media-types/image/" rel="noreferrer">can\'t find</a> the popular <code>image/x-icon</code>. Should that be <code>image/vnd.microsoft.icon</code>?\nAlso the other formats are much shorter.</p>\n\n<p>compare 265 bytes vs 1150 bytes:</p>\n\n<pre><code>data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAAVFBMVEWcZjTcViTMuqT8/vzcYjTkhhTkljT87tz03sRkZmS8mnT03tT89vTsvoTk1sz86uTkekzkjmzkwpT01rTsmnzsplTUwqz89uy0jmzsrmTknkT0zqT3X4fRAAAAbklEQVR4XnXOVw6FIBBAUafQsZfX9r/PB8JoTPT+QE4o01AtMoS8HkALcH8BGmGIAvaXLw0wCqxKz0Q9w1LBfFSiJBzljVerlbYhlBO4dZHM/F3llybncbIC6N+70Q7OlUm7DdO+gKs9gyRwdgd/LOcGXHzLN5gAAAAASUVORK5CYII=\n\ndata:image/x-icon;base64,AAABAAEAEBAAAAEAIABoBAAAFgAAACgAAAAQAAAAIAAAAAEAIAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAD/////ZmZm/2ZmZv9mZmb/ZmZm/2ZmZv9mZmb/ZmZm/2ZmZv9mZmb/ZmZm/2ZmZv9mZmb/ZmZm/2ZmZv///////////2ZmZv9mZmb/ZmZm/2ZmZv9mZmb/ZmZm/2ZmZv9mZmb/ZmZm/2ZmZv9mZmb/ZmZm/2ZmZv9mZmb///////////9mZmb/ZmZm//////////////////////////////////////////////////////9mZmb/ZmZm////////////ZmZm/2ZmZv//////ZmZm/2ZmZv9mZmb/ZmZm/2ZmZv9mZmb/ZmZm/2ZmZv//////ZmZm/2ZmZv///////////2ZmZv9mZmb//////2ZmZv9mZmb/ZmZm/2ZmZv9mZmb/ZmZm/2ZmZv9mZmb//////2ZmZv9mZmb///////////9mZmb/ZmZm////////////////////////////8fX4/8nW5P+twtb/oLjP//////9mZmb/ZmZm////////////////////////////oLjP/3eZu/9pj7T/M2aZ/zNmmf8zZpn/M2aZ/zNmmf///////////////////////////////////////////zNmmf8zZpn/M2aZ/zNmmf8zZpn/d5m7/6C4z/+WwuH/wN/3//////////////////////////////////////+guM//rcLW/8nW5P/x9fj//////9/v+/+w1/X/QZ7m/1Cm6P//////////////////////////////////////////////////////7/f9/4C+7v8xluT/EYbg/zGW5P/A3/f/0933/9Pd9//////////////////////////////////f7/v/YK7q/xGG4P8RhuD/MZbk/7DX9f//////4uj6/zJh2/8yYdv/8PT8////////////////////////////UKbo/xGG4P8xluT/sNf1////////////4uj6/zJh2/8jVtj/e5ro/////////////////////////////////8Df9/+gz/P/////////////////8PT8/0944P8jVtj/bI7l/////////////////////////////////////////////////////////////////2yO5f8jVtj/T3jg//D0/P///////////////////////////////////////////////////////////3ua6P8jVtj/MmHb/+Lo+v////////////////////////////////////////////////////////////D0/P8yYdv/I1bY/9Pd9///////////////////////AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==\n</code></pre>\n'}, {'answer_id': 9742151, 'author': 'thefreeman', 'author_id': 920113, 'author_profile': 'https://Stackoverflow.com/users/920113', 'pm_score': 4, 'selected': False, 'text': "<pre><code>$encoded_data = base64_encode(file_get_contents('path-to-your-image.jpg'));    \n</code></pre>\n"}, {'answer_id': 32372709, 'author': 'Imran Kabir', 'author_id': 3860369, 'author_profile': 'https://Stackoverflow.com/users/3860369', 'pm_score': 3, 'selected': False, 'text': "<p>Check the following example:</p>\n<pre><code>// First get your image\n$imgPath = 'path-to-your-picture/image.jpg';\n$img = base64_encode(file_get_contents($imgPath));\necho '&lt;img width=&quot;100&quot; height=&quot;100&quot; src=&quot;data:image/jpg;base64,'. $img .'&quot; /&gt;'\n</code></pre>\n"}]
['https://Stackoverflow.com/questions/35879', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/115/']