How can I transform a BLOB file into an image using PHP?

2

I need to transform a BLOB file that comes from a MYSQL database to the Image type, to use on my site, I need to do the conversion using PHP, when I use the image in BLOB format, it goes to the whole site in binary .

    
asked by anonymous 18.11.2016 / 18:08

1 answer

2

There are two ways, one is to save the binary on file (which is not interesting) and another is to add to the src of the tag img stating that it is a binary. To do this, simply add data:image/jpeg;base64, followed by binary code.

That is:

<img src="data:image/jpeg;base64,<?= base64_encode($binary) ?>" />

Depending on how you saved (in rare cases) base64_encode can be omitted

    
18.11.2016 / 18:23