1

そこで、このページを作成する PHP コードをここに取り、それを新しい .php ファイルの中に入れて、そのファイルをここにアップロードしました。

画面に大量のゴミ文字が表示されます。何か案は?

以下は、完全な PHP です。

<html>
<head>
    <title></title>
</head>
<body>

<?

// gif is more appropriate than jpg for this kind of image
header("Content-type: image/gif");

// both coupon.jpg and Helvetica.ttf must be located in the same directory as
// dynamic.php or these variables must be updated.
$imgname    = "./coupon.jpg";
$fontname   = "./Helvetica.ttf";

// read image from disk
$im = imagecreatefromjpeg( $imgname )
    or die("Source coupon image has been moved or renamed! Expected coupon.jpg");

// variable allocation
$size       = 11;
$textheight = 250;
$imwidth    = imagesx( $im );
$black      = imagecolorallocate( $im, 0,0,0 );

// create the string containing tomorrow's date
$text       = "Offer expires " .
    date('l\, F j\, Y', mktime(0, 0, 0, date("m")  , date("d")+1, date("Y")))."."; 

// learn the width of the newly allocated string
$bbox       = imagettfbbox( $size, 0, $fontname, $text );
$width      = $bbox[2] - $bbox[0];

// update, display, and clear from memory the newly modified image
imagettftext($im,$size,0,$imwidth/2 - $width/2,$textheight,$black,$fontname,$text);
imagegif($im);
imagedestroy($im);

?>

</body>
</html>

更新の追加: 私の目標は、新しいページ/PHP で生成された画像に Google アナリティクス変換スクリプトを配置することです。それは可能ですか?

4

2 に答える 2

4

何を期待していましたか?HTML を出力してから、いくつかの出力 (つまり、HTML) の後、次のように言います。Content-type: text/plainContent-type: image/gif

PHP の周りの HTML を削除し、PHP だけを残します。

于 2013-03-06T02:28:56.540 に答える
3

PHP コードがイメージを作成します。

この行:

header("Content-type: image/gif");

サーバーの HTTP 応答を変更して、画像を送信していることをブラウザに伝えることができます。したがって、すべての HTML コードは必要ありません。

PHPコードだけを保持する必要があります。

于 2013-03-06T02:32:57.633 に答える