0

テキストを画像に変換するためのこのコードを見つけたので、結果をエコーし​​たかった

<?php
// Set the content-type
header('Content-type: image/png');

// Create the image
$im = imagecreatetruecolor(400, 30);

// Create some colors
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 399, 29, $white);

// The text to draw
$text = 'Testing...';
// Replace path by your own font path
$font = 'arial.ttf';

// Add some shadow to the text
imagettftext($im, 20, 0, 11, 21, $grey, $font, $text);

// Add the text
imagettftext($im, 20, 0, 10, 20, $black, $font, $text);

// Using imagepng() results in clearer text compared with imagejpeg()
imagepng($im);
imagedestroy($im);
?> 

たとえば、そのコードをimage.phpに保存しました。その画像をエコーすることができます

echo"<img src='image.php'>";

しかし、私はそのようにしたくありません。なぜなら、そうした場合、変数テキストを割り当てることができないからです。

そのコードから画像を印刷する他の方法はありますか?

4

1 に答える 1

2

あなたのimage.phpで

交換

 $text = 'Testing...';

 $text=$_GET["text"];

印刷するコード

echo"<img src='image.php?text=AnotherText...'>";

これがあなたが望むものであることを願っていますか?

編集:

<form action="image.php" method="post">
<textarea name="text"></textarea>
<input type="Submit" value="Submit">
</form>

の代わりに image.php ファイルに

$text=$_GET["text"];

使用する

$text=$_POST["text"];
于 2012-08-10T06:10:52.903 に答える