gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 00:39:46 24 4
gpt4 key购买 nike

如何从 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);

最佳答案

试试下面的代码

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

关于php - 如何从php中的字节数组中获取图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53408722/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com