Convert byte array to image and image to byte array in php
I am converting image into byte array and storing byte array in the
database and retrieving the byte array and converting into the image, but
this I am able to do with the image size till 600kib not more than this.
How I should do the above process with image size greater than 600kib. Any
Help will be great.
Thanks in Advance.
What I have done is below:-
to convert image into byte array..
$image = file_get_contents ("uploads/Tulips.jpg");
$array = array();
foreach(str_split($image) as $char){
array_push($array, ord($char));
}
and to convert byte array to image I have done this:-
$imagebytes = explode (',',$bytearray);
$imagestring = call_user_func_array ('sprintf',
array_merge((array)str_repeat('%c', count ($imagebytes)), $imagebytes));
$im = imagecreatefromstring ($imagestring);
if ($im !== false) {
header ('Content-Type: image/png');
imagepng ($im);
imagedestroy ($im);
}
else {
echo 'An error occurred.';
}
No comments:
Post a Comment