【问题标题】:Problems with resizing png's调整png大小的问题
【发布时间】: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() 是否成功。

标签: php resize png


【解决方案1】:

mysql_real_escape_string 需要一个已经打开的 mysql 连接。它将使用最后打开的连接,如果不存在则返回 false。也许这就是您丢失数据的地方。

【讨论】:

  • 我试图删除该功能,但它不起作用。我还尝试在脚本顶部连接到数据库,但它也不起作用:S
猜你喜欢
  • 2013-09-24
  • 2021-09-20
  • 2011-07-05
  • 2013-04-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多