PHP - 从String创建base64编码图像[关闭]

I have array contain strings and I want to display them in image format (each image contain a string). I need display image in format: <img src="data:image/png;base64,...<data>..."/>, all images in a HTML page. How to create base64 encoded image from String?

I tried to search from google, but there are tutorials for "create base64 encoded image from image file".

Example: If my text is "600153957", the output will be:

<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAD4AAAAOCAIAAAD42Ti+AAADv0lEQVRIidVWT0gqaxQ/14ZBRYaMSSLEhEKshYREVAwuQkTETRLiooVEtIgWLUQiwqSFyxZuAhmmCJGQFuJCypW4CJEIEZIWFQViIGVCMflMOG/xdeeaXeXxFu9xf6vD7zu/7/yZ7xzmByLCnwnZ/53Av8eX1A8ODtRq9fPz838WfmFhoa+vb3Z29urqqpvPx8fHXz/x5QB/olKpMAyzsrKCbUgkEkql0m63p1Kpf8JzHHd0dISIzWbTbDarVCqZTLa2tvb09OTxeDQaDUVRUgie5wEgEok4HA69Xt9sNr8LEZFhGCnb+fl5Kdav1JeXlxmGqVarEiOKokajsdvt8Xicoqh4PN6bj0ajABAMBhGxXq/TNK1SqRwORzgcbjabbrc7Go0mEgkAODw8RMSZmZnJyUlEzOfzAHB6evpdiIjX19e5XC4WiwGA0+n8FUtqOU3Tfr+/vYWCIMhksnK5jIhWq9Vqtfbm3W63lHo4HFYqlbVaDb9icXERAARBQES5XL66uoqIjUYDAPb29noIw+GwVPNnLGKFQiEAkMlkJpOJVI+IDodjamqK2D6fj2XZ3jwiSqmbTKaJiYm7uzvp6O3tjdRmNptFUURElmW3t7clYSgU+q2QwGazURTVXtLnmCaTSZZlU6mU0+l0uVwPDw8AcHFxYTKZiANFUfV6ndjd+HbQNF0qlQwGw87ODgA8Pj4ajUbywARBUCgUAOD1ekul0svLy/7+PgDo9frvQoLX19dMJmOxWNRqdeeYqlQqMj3k25FHRlHU5uYmcfB6vQzDELsb3951RKzValtbWwCQSqVubm4AQC6XA4BWqyUTJYqizWaTSpXGrF1ImJOTE+lFdXa91WoNDQ0BAGmhKIoA0N/f32q1iMPl5aXRaCR2N74DarXa7/cDQKFQGB0dvb+/f39/LxQK5XKZDLRCoTg7O8vn8wMDAx6PZ3Bw8LuQMOl0GgDsdnv7/Z+pj42NkXTJBpiengaAubm5YrEIALe3t8ViUVJ2478jGAwCAMdxADAyMgIAyWQSAEibCHiebzQau7u73YQAkMvldDrd+Pj4l9ulMTUYDLFYjGVZjuMImc1maZoWBMFiscjlcrJSevDtDyabzS4tLQEA2VrVajWdThPGYrGQFY6Ix8fHABCJRKQbOoQEcrl8fX29Y3A/U2+1Wj6fj2EYjuMqlYp0zPP88PAwy7LS8u7Nu91usjRcLpdWq+V5nvCZTIZhGJ1OFwgEGo2G5B8IBDY2Ntpv6BASmM3m8/PzjtR/4B/7+/U3c4foNnBzZrIAAAAASUVORK5CYII=">

Live example: http://goo.gl/mYBUI . I want protect my numbers like this website. By this way, the spam software which scan text to find this numbers can't read them.

Please help me! Sorry for my bad English.

This is just a rough example of how you could do what you want, you need to generate the image with php using whatever data you want and then get the file contents as a string

You'll get the idea if you run this code as it is.

<?php

    function b64img( $str, $fs=10, $w=250, $h=200, $b=array( 'r'=>255, 'g'=>255, 'b'=>255 ), $t=array('r'=>0, 'g'=>0, 'b'=>0) ){
        $tmp=tempnam( sys_get_temp_dir(), 'img' );

        $image = imagecreate( $w, $h );
        $bck = imagecolorallocate( $image, $b['r'], $b['g'], $b['b'] );
        $txt = imagecolorallocate( $image, $t['r'], $t['g'], $t['b'] );

        imagestring( $image, $fs, 0, 0, $str, $txt );
        imagepng( $image, $tmp );
        imagedestroy( $image );

        $data=base64_encode( file_get_contents( $tmp ) );
        @unlink( $tmp );
        return $data;
    }


    $img=b64img( 'Some text to make into base64 image', 6, 400, 100 );
    echo "<img src='data:image/png;base64, {$img}' />";

    $img=b64img( 'Another image', 10, 200, 200, array('r'=>0, 'g'=>255, 'b'=>0), array('r'=>255, 'g'=>0, 'b'=>0) );
    echo "<img src='data:image/png;base64, {$img}' />";
?>

Check whether below code helps you

$decodeString=base64_decode($imageString);
$imageCreated=imagecreatefromstring($decodeString);
ob_start();
imagepng($imageCreated);
$imgPng = ob_get_clean();
$imgPath = "data:image/png;base64," . base64_encode($imgPng);

and $imgPath can be used as src for .