Image to binary and binary to image conversion in php

Suppose that you have test.jpg image in your localhost. You want to convert your image into binary and after then vice-versa. So, let enjoy…

Image to binary conversion:


<? php

$image_data=file_get_contents('test.jpg');

$encoded_image=base64_encode($image_data);

echo $encoded_image;

?>

Binary to image conversion:


<?php

$image_data=file_get_contents('test.jpg');

$encoded_image=base64_encode($image_data);

$decoded_image=base64_decode($encoded_image);

echo $decoded_image;

?>

Advertisements

Software Engineer at The Jaxara IT Ltd , Dhaka , Bangladesh

Tagged with: ,
Posted in PHP
7 comments on “Image to binary and binary to image conversion in php
  1. Vijay Raj says:

    why i am not getting image form database .i am only getting binary data…please help me..

    Following is my code…

    <img src="” height=”200″ width=”200″ />

  2. jitendra says:

    please tell me how to show image from binary data

  3. Dhiraj says:

    Image gets converted to string than again it should be converted to binary(0101010) so please provide tat code so that it can be reversed to get image…..

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: