0
in front-end I have the following code
$separador = explode('ID = ', $data['produto_nome']);
$produtoSelecionado = $wpdb->get_results( "SELECT * FROM gs_produtos WHERE id = '$separador[1]'" );
echo '<img src="'.get_bloginfo( 'template_url' ).'/voucher.php">';
In the voucher.php file I have the following code
// Header informando que é uma imagem JPEG
header( 'Content-type: image/jpeg' );
if( $produtoSelecionado ){
foreach( $produtoSelecionado as $voucher );
$path = get_bloginfo( 'template_url' ).$voucher->voucher;
// PEGA URL DA IMAGEM NO BANCO DE DADOS
$voucherCliente = imagecreatefromjpeg( $path );
// CORES DA SAIDA DA IMAGEM
$cor = imagecolorallocate( $voucherCliente, 255, 255, 255 );
// TEXTO 01 - ESCRITO NA IMAGEM
$nome = urldecode( ucfirst( $data['userName'] ) );
// ESCREVENDO NA IMAGEM
imagestring( $voucherCliente, 5, 15, 515, $nome, $cor );
// ENVIA IMAGEM PARA O BROWSER OU ARQUIVO
imagejpeg( $voucherCliente, NULL, 80 );
}
tried several ways, but the image does not appear, just appears that icon of corrupted image, it is the first time I use this lib and I am not able to present the image.
Try to comment on the
header( 'Content-type: image/jpeg' );
and see if there are any error messages. In PHP error_log there appears some error related?– Thomas
@Thomas shows no error, but in the browser console it says that the image was transferred as text/html
– Pablo Campina
Try to put
ini_set('display_errors', 1); error_reporting(E_ALL);
before theheader()
and comment the header. I believe this will show the possible errors.– Thomas
@Thomas remains error-free
– Pablo Campina
he gets to enter the if?
– Thomas
@Thomas enters the if tranquil, if I try to make a include() he tries to print something that starts like this, which are many characters that possibly should be the image JFIF ;CREATOR: Gd-jpeg v1.0 (using IJG JPEG V80), quality = 80 C %# , #&')*)-0-(0%()( C (((((((((((((((((((((((((((((((((((((((((((((((((((��%a"�� ��� }! 1AQa"Q2 #B R $3br
– Pablo Campina
adding ob_start(); anted from imagejpeg() and this after it $rawImageBytes = ob_get_clean(); echo "<img src='data:image/jpeg;Base64," . base64_encode( $rawImageBytes ) . " ' />"; I was able to display the image, but without the text I want to write in it
– Pablo Campina