2013-11-01 103 views
2

好吧,這裏的問題。此代碼工作在本地主機上,但不能在活動網站PHP - 代碼工作在本地主機上,但不能在活動網站

<?php 
session_start(); 
header('Content-type: image/jpeg'); 

$text = $_SESSION['secure']; 
$font_size = 30; 
$image_width = 120; 
$image_height = 40; 
$image = imagecreate($image_width, $image_height); 
imagecolorallocate($image, 255, 255, 255); 
$text_color = imagecolorallocate($image, 0, 0, 0); 
$line_color = imagecolorallocate($image, 0, 0, 0); 

for($x=1; $x<=30; $x++){ 
    $x1 = rand(1, 100); 
    $y1 = rand(1, 100); 
    $x2 = rand(1, 100); 
    $y2 = rand(1, 100); 
    imageline($image, $x1, $y1, $x2, $y2, $line_color); 
} 

imagettftext($image, $font_size, 0, 15, 30, $text_color, 'font2.ttf', $text); 
imagejpeg($image); 
?> 

本地主機和主機商都運行相同的PHP版本

看看這幅畫你張貼任何之前,請!:

http://s2.postimg.org/etamdsk95/help_me.png

+2

問題與PHP擴展;) – Hackerman

+0

發表您的php.ini – Joren

+3

的內容已在遠程服務器上得到了安裝並啓用了GD擴展? – Gavin

回答

0

嘗試看看error.log中(APACHE),也有可能是 可能有一個會話的問題,你可以 嘗試使用「隱藏所有錯誤的error_reporting(0);

試試這個:

<?php 
@session_start(); 
error_reporting(0); 
@header('Content-type: image/jpeg'); 

$text = $_SESSION['secure']; 
$font_size = 30; 

$image_width = 120; 
$image_height = 40; 

$image = imagecreate($image_width, $image_height); 
imagecolorallocate($image, 255, 255, 255); 
$text_color = imagecolorallocate($image, 0, 0, 0); 
$line_color = imagecolorallocate($image, 0, 0, 0); 

for ($x=1; $x<=30; $x++) { 
$x1 = rand(1, 100); 
$y1 = rand(1, 100); 
$x2 = rand(1, 100); 
$y2 = rand(1, 100); 

imageline($image, $x1, $y1, $x2, $y2, $line_color); 
} 

imagettftext($image, $font_size, 0, 15, 30, $text_color, 'font2.ttf', $text); 
imagejpeg($image); 

?> 

但最好的,會修正這個錯誤,所以看@ error.log中

http://php.net/manual/en/function.error-reporting.php

如果你有任何的錯誤信息,你可以告訴我們 - 所以我們會盡力幫助你:)

0

你的代碼有一些錯誤,但它不是PHPGD lib錯誤,請注意下面的代碼:

<?php 
//session_start(); 
header('Content-Type: image/jpeg'); 
//$_SESSION['secure']; disabled, this will lead to notice: undefined index 
$text = "he123"; 
$font_size = 30; 
$image_width = 120; 
$image_height = 40; 

$image = imagecreate($image_width, $image_height) or die("Cannot Initialize new GD image stream"); 
$background_color = imagecolorallocate($image, 255, 255, 255); //add background color 
$text_color = imagecolorallocate($image, 255, 0, 0); //red for the text 
$line_color = imagecolorallocate($image, 0,255,0); // green for the line 

for($x=1; $x<=30; $x++) { 
    $x1 = rand(1, 100); 
    $y1 = rand(1, 100); 
    $x2 = rand(1, 100); 
    $y2 = rand(1, 100); 
    imageline($image, $x1, $y1, $x2, $y2, $line_color); 
} 

// add ./ to the font name 
imagettftext($image, $font_size, 0, 15, 30, $text_color, "./font2.ttf", $text); 
imagejpeg($image); 
imagedestroy($image); // remember to clear the chace :p 
?> 

這裏的output

+0

這就像一個魅力!謝謝! – he123

相關問題