php imagepng()仅在服务器上生成黑色图像

php imagepng()仅在服务器上生成黑色图像,php,javascript,apache,Php,Javascript,Apache,我使用基于以下脚本的脚本,从用户上传的声音文件动态生成波形图像: 该脚本在我的开发环境Windows7、Apache2和PHP5上运行良好。但是当我把它放在我的服务器UbuntuLinux,Apache2 PHP5上时,imagepng()输出一个黑匣子 我已经研究过类似的问题,例如,并确保我的imagealphablending()和imagesavealpha()以所描述的方式使用。但还是没有运气。我已经检查了文件夹权限,并确认LAME可以写入正确的文件夹而不会引发错误 我还尝试简单地将背景

我使用基于以下脚本的脚本,从用户上传的声音文件动态生成波形图像:

该脚本在我的开发环境Windows7、Apache2和PHP5上运行良好。但是当我把它放在我的服务器UbuntuLinux,Apache2 PHP5上时,imagepng()输出一个黑匣子

我已经研究过类似的问题,例如,并确保我的imagealphablending()和imagesavealpha()以所描述的方式使用。但还是没有运气。我已经检查了文件夹权限,并确认LAME可以写入正确的文件夹而不会引发错误

我还尝试简单地将背景颜色设置为与我的页面背景颜色相同的颜色,因为透明度是“很好的选择”,而不是必须的

总之,下面是输出我的图像的PHP:

// want it resized?
if ($width) {
  // resample the image to the proportions defined in the form
  $rimg = imagecreatetruecolor($width, $height);
  // save alpha from original image
  imagealphablending($rimg, false);
  imagesavealpha($rimg, true);
  // copy to resized
  imagecopyresampled($rimg, $img, 0, 0, 0, 0, $width, $height, imagesx($img), imagesy($img));
  imagepng($rimg, "../img/" . $genFileName .".png");
  imagedestroy($rimg);
} else {
  imagealphablending($img, false);
  imagesavealpha($img, true);
  imagepng($img, "../img/" . $genFileName .".png");
}

imagedestroy($img);

echo "img/" . $genFileName . ".png";


} else {

echo "An error.";


}
这是调用它的Javascript:

//pass the audio data to the server to have the wave drawn
_generateWaveForm = function(_file){

//create the form data
_form.append('file',_file);                      //mp3 to be sent to the server
_form.append('height',300);                      //height of image to be returned
_form.append('width',window.innerWidth - 20);    //width of image to be returned
_form.append('foreground','#FFFF51');            //color of image to be returned
_form.append('background','');                   //background (left empty for transparent BG)
_form.append('flat',true);                       //setting flat to true

    //pass it on
    $.ajax({
        url: "php/php-waveform-png_3.php",
    type: "POST",
    data: _form,
    processData: false,
    contentType: false,
    success: function(_result){_gotTheWaveForm(_result)}
    });
},
这两天来,我一直在绞尽脑汁,任何帮助都将不胜感激。

尝试添加

$transparentColor = imagecolorallocatealpha($rimg, 0, 0, 0, 127);
imagefill($rimg, 0, 0, $transparentColor);

整个部分:

$rimg = imagecreatetruecolor($width, $height);
imagealphablending($rimg, false);
imagesavealpha($rimg, true);
$transparentColor = imagecolorallocatealpha($rimg, 0, 0, 0, 127);
imagefill($rimg, 0, 0, $transparentColor);

您应该尝试将代码减少到相关部分。好的,
imagecreatetruecolor
会创建一个黑色图像。我已经尝试过了,但没有成功。在这一点上,我非常确定它与脚本本身的关系不大,而更多地与我的WAMP和LAMP堆栈之间的环境差异有关。
$rimg = imagecreatetruecolor($width, $height);
imagealphablending($rimg, false);
imagesavealpha($rimg, true);
$transparentColor = imagecolorallocatealpha($rimg, 0, 0, 0, 127);
imagefill($rimg, 0, 0, $transparentColor);