From what you explained, I imagine your variable $result['imagem']
has the 'binary' of the image, to make a quick comparison would be as if you were running a file_get_contents('minhaimagem.gif')
and playing for that variable, so it works when you put:
Header( "Content-type: image/gif");
echo $foto; // <- $foto é equivalente ao dado de um file_get_contents('minhaimagem.gif')
In other words, your file php is playing the role of a file named in .gif
. That said now you should already understand that when you add the tag div
, or anything else to this 'binary' data you are transforming your image into a corrupt image as shown below:
Header( "Content-type: image/gif");
echo "<div>$foto</div>";
This is the same thing as you open an image as text file, write something, save and then try to open it as image.
Solution 1
You can create another file and in it add the tag img
passing as src
the name of the file that is making the image paper.
Example:
Imagining that this file is called minha_imagem.php
Header( "Content-type: image/gif");
echo $foto;
Creates a new file called pagina.php
or pagina.html
and add the following code:
<html>
<head></head>
<body>
<img src='minha_imagem.php'/>
</body>
</html>
Solution 2
Make a function that takes the 'binary' of the image and turns it into a dataURI
function dataURI( $bin )
{
return 'data: image/gif;base64,'.base64_encode( $bin );
// ^ ^
// | Estou imaginando que seja um gif
// Vai gerar algo como "data: image/gif;base64,/9j/4AAQSkZJRgABAg...+LJGj21jxe//9k="
// ^
// Isso é uma string longa eu removi parte aqui
// essa string pode ser utilizada como 'src' de uma imagem
}
If you have the image file name you can use a function like the mime_content_type ( $nome_do_arquivo )
to get that information image/gif
And use it on your page as shown in the example:
require_once '../customers/functions.php';
require_once(DBAPI);
$database =open_database();
$sql = "SELECT id, imagem FROM gema_vitrine WHERE id = 4";
$query = $database->query($sql);
$result = $query->fetch_assoc();
$foto = $result['imagem'];
// Header( "Content-type: image/gif");
function dataURI( $bin )
{
return 'data: image/gif;base64,'.base64_encode( $bin );
}
$foto = dataURI($foto);
echo "<div> <img src='$foto'/> </div>";
I used the first solution and it worked, and I imagine it will marry well with what I intend to do, thank you very much!
– Douglas da Dias Silva