how to create a base64encoded string from image resource

后端 未结 1 1224
遥遥无期
遥遥无期 2020-11-29 12:17

I have sent a base64 encoded string via AJAX to PHP and created an image resource with imagecreatefromstring - all is fine.

Now I want to get the base64

相关标签:
1条回答
  • 2020-11-29 12:43

    Taken from http://www.php.net/manual/en/book.image.php#93393

    $image = imagecreatefromstring($file);
    
    // start buffering
    ob_start();
    imagepng($image);
    $contents =  ob_get_clean();
    
    echo "<img src='data:image/png;base64,".base64_encode($contents)."' />";
    
    imagedestroy($image);
    
    0 讨论(0)
提交回复
热议问题