I have a PHP script that generates a PNG captcha(set by Content-Type header).It can be embedded in an HTML page by just using img. I want to convert that image to base64 format for displaying.How do I go about doing that ?

Using the normal method for encoding as given on Wikipedia's article(Click Here) doesn't work.

Member Avatar for LastMitch

I have a PHP script that generates a PNG captcha(set by Content-Type header).It

I haven't done this before but you can try this.

Have you try to put the data on an xml element?

<?php
$img = file_get_contents('captcha.png');
$imgdata = base64_encode($img);  
?>

Then your xml tags should be like this:

<image width="25" height="25">data:image/png;base64,imageData</image>

or you can take a look at this:

http://shashankbhide.wordpress.com/2011/11/15/base64-encoded-image-based-captcha-control/

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.