PHP HTML image output

后端 未结 4 1224
终归单人心
终归单人心 2021-02-08 08:02

In the PHP manual for base64_encode() I saw the following script for outputting an image.



        
4条回答
  •  不知归路
    2021-02-08 08:30

    Ok, sorry, I was thinking too fast :)

    imagepng() will output raw data stream directly to the browser, so you must use ob_start() and other output buffering handles to obtain it.

    Here you are:

    ob_start();
    imagepng($yourGdImageHandle);
    $output = ob_get_contents();
    ob_end_clean();
    

    That is - you need to use $output variable for you base64_encode() function.

提交回复
热议问题