1

I am making a form which the user is filling to create a mail signature:

generatarjeta.php

if(isset($_GET["suc"]) && $_GET["suc"] !="")
{ $code="";
  foreach($_GET as $key => $value){
    $code.= $key . "=" . $value . "&";
  }
  $code = rtrim($code,"&");
  ?>
  <img src="imagem.php?<?php echo $code;?>">
  <script>window.history.pushState("", "", '/generatarjeta.php');</script>
  <?php exit();
}

<form method="get">
      <table>
        <tr><td><label>Sucursal</label></td><td><select name="suc">
          <option value="">Seleccione...</option>
          <?php
          $con_sucursal = mssql_query("select * from localitos where local NOT IN (3,5, 7,12, 13, 14,15,16,17,19, 20, 21, 22,23,24,25,26,27)");
          while ($res_sucursal = mssql_fetch_array($con_sucursal))
          {
            echo "<option value='$res_sucursal[0]'>$res_sucursal[1]</option>";
          }?>
        </select></td></tr>
        <tr><td><label>Nombre del Trabajador: </label></td><td><input type="text" name="nombre" required="" onkeypress="return textonly(event);"/></td></tr>
        <tr><td><label>Puesto: </label></td><td><input type="text" name="puesto" required="" onkeypress="return textonly(event);"/></td></tr>
        <tr><td><label>Telefono: </label></td><td><input type="text" name="tel" required="" onkeypress='return solonums(event)'/>&nbsp;<label>Extension: </label><input type="text" name="ext" onkeypress='return solonums(event)'/></td></tr>
        <tr><td><label>correo: </label></td><td><input type="text" name="mail" placeholder="nombre.apellido"/></td></tr>
        <tr><td><input type="submit" name="submit" value="Generar"/></td><td><input type="reset"/></td></tr>
      </table>
    </form>

imagem.php

//Carregar imagem
$rImg = ImageCreateFromJPEG("the_firma.jpg");
//Definir cor
$cor = imagecolorallocate($rImg, 226, 41, 34);
$cor2 = imagecolorallocate($rImg, 60, 60, 59);

$tel = "$_GET[tel] Ext. $_GET[ext]";
$correo = "$_GET[mail]@mail.x";
//Escrever nome
imagettftext($rImg,14,0,850,60,$cor,'Open Sans',$_GET["nombre"]);
//imagestring($rImg,5,850,60,urldecode($_GET["nombre"]),$cor);
//imagestring($rImg,5,850,80,urldecode($_GET["puesto"]),$cor2);
//imagestring($rImg,5,800,120,urldecode($tel),$cor2);
//imagestring($rImg,5,800,140,urldecode($correo),$cor2);
//Header e output
header('Content-type: image/jpeg');
imagejpeg($rImg,NULL,100);

My issue is, when I use imagestring, everything works fine, but I need to use Open Sans ttf so I tried to use imagettftext, but it "echoes" an empty result or error when loading img src and also when testing file separately it doesnt show any error.

Any suggestions?

UPDATE:

$tel = "$_GET[tel] Ext. $_GET[ext]";
$correo = "$_GET[mail]@mail.mx";
$puesto = strtoupper($_GET["puesto"]);


imagettftext($rImg, 14, 0, 780,60, $cor, 'OpenSans-Bold.ttf', $_GET['nombre']); (WORKS)
imagettftext($rImg, 8, 0, 780,80, $cor2, 'OpenSans-Regular.ttf', $puesto); (WORKS)
imagettftext($rImg,9,780,135,$cor2, 'OpenSans-Regular.ttf',urldecode($_GET["tel"])); (CRASHES)
imagettftext($rImg,9,780,172,$cor2,'OpenSans-Regular.ttf',$correo);(CRASHES)
imagettftext($rImg,8,780,209,$cor2,'OpenSans-Regular.ttf',$_GET["direccion"]);(CRASHES)
imagettftext($rImg,8,780,223,$cor2,'OpenSans-Regular.ttf',$_GET["dir2"]);(CRASHES)
Neobugu
  • 333
  • 6
  • 15

1 Answers1

0

As documented, the $fontfile parameter needs a path to the font file, not its display name:

The path to the TrueType font you wish to use.

The simplest solution is to put the .ttf file (opensans.ttf?) in the same folder as your script and then change your function call like so:

imagettftext($rImg, 14, 0, 850, 60, $cor, 'opensans.ttf', $_GET['nombre']);
timclutton
  • 12,682
  • 3
  • 33
  • 43