I'm using the GD Library, I have the code below and I want to put a line break $texto = "primeira linha\nsegunda linha";
, however it needs to pass $get
.
What I mean by going through $get
is that if you replace the line
$texto = $_GET['texto'];
by
$texto = "linha1\n linha2";
In the file img.php
the \n
will break the line and using the form in method get
the text stays on the same line.
How to fix this?
index.php
<?php $go = isset($_GET['texto'])?$_GET['texto']:"primeira linha\nsegunda linha";?>
<form method="get">
<input name="texto" type="text" value="<?php echo $go ?>" size="100"/>
<input type="submit" value="Criar imagem" />
</form>
<img src="img.php?texto=<?php echo $go ?>" />
img.php
<?php
$tamfonte = 25;
$fonte = 'verdana.ttf';
$texto = $_GET['texto'];
$img = imagettfbbox($tamfonte, 0, $fonte, $texto);
$largura = "600";
$altura = "400";
$imagem = imagecreate($largura, $altura);
imagecolorallocate($imagem, 255, 255, 255);
$corfonte = imagecolorallocate($imagem, 0, 0, 0);
imagefttext($imagem, $tamfonte, 0, 0, abs($img[5]), $corfonte, $fonte, $texto);
header( 'Content-type: image/jpeg' );
imagejpeg($imagem, NULL, 100); ?>