Wednesday, 29 April 2015

Convert image to Binary Data and vice versa in PHP

 Convert image to Binary Data and vice versa in PHP

How to Convert image to Binary Data
$imageURL ='http://www.aboutcity.net/images/web-technology-experts-notes.jpg';
$contents = base64_encode(file_get_contents($imageURL));
/** Now stored the $contentes in Database or In Server**/


/** Now stored the $contentes in Database or In Server**/


How to display the Binary image data in Browser.
/** get the binary image data and stored in $contents variable **/
$contents='BINARY IMAGE DATA';
 echo "<img src="data:image/jpg;charset=utf8;base64,$contents" />";


How to get the image size (Height and Width) from binary data 
$file ='http://www.aboutcity.net/images/web-technology-experts-notes.jpg';
$contents = file_get_contents($file);
          
$image = imagecreatefromstring($contents);
echo 'Width: '.imagesx($image);
echo "\n";
echo 'Height: '.imagesy($image);