http://andrewfreiday.com/2010/04/29/generated-mp3-waveforms-with-php/に基づいたスクリプトを使用して、ユーザーがアップロードしたサウンドファイルから波形画像を動的に生成しています。
スクリプトは、開発環境Windows 7、Apache2、PHP 5で正常に機能します。ただし、サーバーにUbuntu Linux、Apache2 PHP 5を配置すると、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)}
});
},
私はこれに2日間頭をぶつけてきました、どんな助けでもありがたいです。