I'm working on a wordpress project, and I need to dynamically generate an image using PHP's imagecreatefromjpeg () function in addition to the imagettftext () function to add custom text in the image, with fonts of my choice.
The script that I developed works perfectly, but when I try to use it inside the wordpress page I can not get the source.
Code sample (works):
<?php
/*---------------------------------------*/
// Header informando que é uma imagem JPEG
header( 'Content-type: image/jpeg' );
// Carregar imagem já existente no servidor
$imagem = imagecreatefromjpeg( "cupomFinal.jpg" );
$cor = imagecolorallocate($imagem, 119, 119, 119);
$corTitle = imagecolorallocate($imagem, 163, 72, 177);
// Texto que será escrito na imagem
$nome = "Cliente: Vinicius Ribeiro";
$email = "Email: [email protected]";
$contato = "Contato: 31-0000-0000";
$codigo = "Código:";
$codigoDesconto = "00000-00-000-2015";
$font = 'RobotoCondensed-Regular.ttf';
$fontCodigo = 'impact.ttf';
// INSERE OS TEXTOS NA IMAGEM COM AS FONTES ESCOLHIDAS
imagettftext($imagem, 16, 0, 390, 140, $cor, $font, $nome);
imagettftext($imagem, 13, 0, 390, 170, $cor, $font, $email);
imagettftext($imagem, 13, 0, 390, 200, $cor, $font, $contato);
imagettftext($imagem, 12, 0, 50, 170, $corTitle, $fontCodigo, $codigo);
imagettftext($imagem, 18, 0, 50, 200, $corTitle, $fontCodigo, $codigoDesconto);
// eEnvia a imagem para o borwser ou arquivo
imagejpeg( $imagem, NULL, 90);
imagedestroy($imagem);
?>
The code above was tested separately and worked perfectly, but when I try to implement within wordpress, the font is never found!
As the command "header" indicates that the page will be an image, just comment to see the errors. So I visualized the following return:
I have tried to use multiple paths to the source and all to no avail.
In some attempts, I used the imagestring () function that also writes in the image, but without the custom font, and the script worked perfectly with the syntax below:
imagestring($imagem, 5, 390, 170, $email, $cor);
But it would be extremely important that I use the custom font.
Thank you in advance for the help.
Hug.