PHP将blob写入文件

PHP将blob写入文件,php,image,Php,Image,我有以下代码: echo "<img src='data:image;base64,".$apprentice[0][6]." '>"; echo”“; 它呼应出画面$学徒[0][6]似乎是一个图像字符串。它看起来像:/9j/4SyvRXhp 我想将图像写入person.jpg文件。我认为解决方案是使用文件内容('person.jpg',$image)。但我不知道如何将这个imagestring或其他任何东西转换为$image 有人知道如何变换这个图像吗?我尝试使用imagecr

我有以下代码:

echo "<img src='data:image;base64,".$apprentice[0][6]." '>";
echo”“;
它呼应出画面$学徒[0][6]似乎是一个图像字符串。它看起来像:/9j/4SyvRXhp

我想将图像写入person.jpg文件。我认为解决方案是使用
文件内容('person.jpg',$image)
。但我不知道如何将这个imagestring或其他任何东西转换为$image

有人知道如何变换这个图像吗?我尝试使用imagecreatefromstring(),但不起作用


感谢您的帮助。

下面是如何从PHP创建JPG图像文件的示例

<?php
// Create a blank image and add some text
$im = imagecreatetruecolor(120, 20);
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 1, 5, 5,  $apprentice[0][6], $text_color);

// Set the content type header - in this case image/jpeg
header('Content-Type: image/jpeg');

// Output the image
imagejpeg($im);

// Free up memory
imagedestroy($im);
?>


来源:

base64\u decode
就可以了——尽管我很惊讶你的原始代码可以工作,因为没有类型。应该是
数据:image/png;base64,…
数据:图像/jpeg;base64,…