Create the image in PHP with imagecreatefromstring
$image = imagecreatefromstring(base64_decode($row['x']));
Next, use imagescale
to resize the image.
$image = imagescale($image, 100, 100);
Set the appropriate header:
header('Content-Type: image/jpeg');
Output the image with imagejpeg
:
imagejpeg($image);
Free up memory by destroying the image with imagedestroy
:
imagedestroy($image);
Now point your <img />
to this PHP file.
Alternatively, if putting that logic in its own file doesn't work for you, you can use Output Buffering to capture the output of the image as seen in this StackOverflow answer, and then place it directly in the src
attribute.
It would go something like this:
$image = imagecreatefromstring(base64_decode($row['x']));
$image = imagescale($image, 100, 100);
ob_start();
imagejpeg($image);
$contents = ob_get_contents();
ob_end_clean();
echo "<img src='data:image/jpeg;base64,".base64_encode($contents)."' />";
imagedestroy($image);