PHP将blob写入文件

I have the following code:

echo "<img src='data:image;base64,".$apprentice[0][6]." '>";

It echoes out the picture. $apprentice[0][6] seems to be a image string. It looks like: /9j/4SyvRXhp...

I would like to write the image to the file person.jpg. I think the solution is something with file_put_contents('person.jpg', $image). But i dont know how to transform this imagestring or whatever it is to $image.

Does somebody know how to transform this image? I tried using imagecreatefromstring() but it did not work.

Thanks for your help.

Below is the sample of how to create a JPG image file from PHP.

<?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);
?>

Source : PHP Image creation