我在做這在用戶填寫創建郵件簽名形式:如何正確使用imagettftext?
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)'/> <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);
我的問題是,當我使用和imagestring ,一切工作正常,但我需要使用Open Sans ttf,所以我試圖使用imagettftext,但它加載img src時,「回聲」一個空的結果或錯誤,也單獨測試文件時,它不顯示任何錯誤。
有什麼建議嗎?
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)
它看起來正確的給我。你確定你的變量是正確的嗎?你有沒有嘗試過var_dump(urldecode($ correo));? – Andreas
$ correo與imagestring無法正常工作,而不是imagettftext – Rhopercy