0
我遇到了使用此腳本調整我的Minecraft皮膚的問題。 當我在本地主機上測試它時,一切正常,但是當我將它上傳到我的服務器時,它只顯示調整大小的透明圖像,沒有內容。 這裏的腳本:調整png的大小問題
<?php
function clean($str) {
$str = @trim($str);
if(get_magic_quotes_gpc()) {
$str = stripslashes($str);
}
return mysql_real_escape_string($str);
}
// File and new size
$fil = clean($_GET['skin']);
header('Content-type: image/png');
//$myimage = resizeImage('filename', 'newwidthmax', 'newheightmax');
function resizeImage($filename, $newwidth, $newheight){
list($width, $height) = getimagesize($filename);
$thumb = imagecreatetruecolor($newwidth, $newheight);
$transparent = imagecolorallocate($thumb, 200, 255, 200);
imagefill($thumb, 0, 0, $transparent);
imagecolortransparent($thumb, $transparent);
$source = imagecreatefrompng($filename);
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
return imagepng($thumb);
}
$myimage = resizeImage($fil, '640', '320');
print $myimage;
?>
您可以在這裏看到的輸出:link
當你調用'resizeImage()'的時候'$ fil'實際上被填滿了嗎?你的'clean()'函數通過'mysql_real_escape_string()'函數,如果沒有活動的mysql連接,它將會失敗。如果您將'error_reporting(E_ALL)'設置爲最高,它應該爲您分配E_WARNINGs。 – Fanis 2011-05-04 19:41:24
你可能還想檢查你的本地主機和服務器是否運行相同版本的GD,更重要的是'$ filename'是可讀的,'imagecreatefrompng()'是成功的。 – Orbling 2011-05-04 21:15:45