2

How to get image from bytes array in php ? i have string of byte array and i want to generate a image.

I have tries this code below.

$arrayData = array(
    'status' => 404,
    'message' => 'Not Found'
);

$json = file_get_contents('php://input');
$obj = json_decode($json,true);


$img = isset($obj['image']) ? $obj['image'] : '';  


print_r($img); die;


$filename = $finalimage . '.' . 'jpg';

$filepath = base_url().'uploads/apifiles'.$filename;



file_put_contents($filepath, $finalimage);

1 Answer 1

6

Try this code below

$image_string = 'byte_strng';
$data = base64_decode($image_string);
$im = imagecreatefromstring($data);
header('Content-Type: image/jpeg');
imagejpeg($im);
imagedestroy($im);
Sign up to request clarification or add additional context in comments.

3 Comments

That was quick. You answered within 40 seconds from the question was asked. Did you have the answer in your CTRL + V pretyped?
Hey vishal you are going good but you forgot '$' before 'byte_string' :)
No, Coolbuddy its string.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.