如何从php中的字节数组中获取图像?

Asp*_*est 2 php codeigniter

如何从php中的字节数组中获取图像?我有字节数组的字符串,我想生成一个图像.

我在下面试过这段代码.

$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);
Run Code Online (Sandbox Code Playgroud)

vis*_*ani 5

请尝试以下代码

$image_string = 'byte_strng';
$data = base64_decode($image_string);
$im = imagecreatefromstring($data);
header('Content-Type: image/jpeg');
imagejpeg($im);
imagedestroy($im);
Run Code Online (Sandbox Code Playgroud)

  • 嘿vishal你很顺利,但你在'byte_string'之前忘了'$':) (2认同)