Saturday, June 5, 2010

How to convert base64 string into image with php?

 First of all create the base64 string
 
  function encode_img($img)
      {
           $fd = fopen ($img, 'rb');
           $size=filesize ($img);
           $cont = fread ($fd, $size);
           fclose ($fd);
           $encimg = base64_encode($cont);
           return $encimg;
       }
     
         $image_base64=encode_img('123.jpg'); // to encode the image
 
then convert back to image into some location
 
$img = imagecreatefromstring(base64_decode($image_base64));
    if($img != false)
    {
    imagejpeg($img, 'user_images/image.jpg');
    }


Have Dream Day

3 comments:

  1. thankuuuuuuuuuuuuuuuuuuuuuuuuuuuu...............sooooooooooooo...............mucccccchhhhhhhhhhh

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete