Is it possible, like through src in <img src="/test.php" alt=""> to get the answer in base64 and display the image

  • can. to be beautiful, do <img src="/test.png" alt=""> , in htaccess translate test.png to test.php and process base64 in php - Saidolim
  • @Saidolim write a response with an example .htaccess add karma - Serge Esmanovich
  • just one moment clarify the meaning of the получить ответ в base64 и вывести изображение - Saidolim
  • @Saidolim Yes, you understood me correctly, get a base64 response and display the image, the request should be sent by src - Serge Esmanovich

2 answers 2

If you just want to give a picture from a .php file, you need to remember

 header('Content-Type: image/jpeg'); 

If you plan to give the base64 browser, it will turn out badly - the browser somehow doesn’t really understand base64 as a file, and the file itself will swell to a third when encoded into this view.

But if you want to insert a small picture, then you generally need to insert a link to the picture at the stage of page generation, but the picture itself (just do not forget to specify gif / jpg / png mime type correctly), such code :

 <img src="data:image/gif;base64,___а_тут_собственно_кодированное в b64__" /> 

If you want to work with a picture using a browser and suddenly you want base64, the answer has already flown

    You can try this:

     $binary = base64_decode($base64_image); $image= imagecreatefromstring($binary); header('Content-Type: image/jpeg'); imagejpeg($image); imagedestroy($image);