【发布时间】:2011-08-18 19:20:12
【问题描述】:
我在使用此脚本调整我的 Minecraft 皮肤大小时遇到问题。 当我在我的本地主机上测试它时,一切正常 100%,但是当我将它上传到我的服务器时,它只显示一个调整大小的透明图像,没有内容。 这是脚本:
<?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_WARNING。 -
您可能还想检查您的 localhost 和服务器是否运行相同版本的 GD,更重要的是,
$filename是否可读,imagecreatefrompng()是否成功。