PHP imagepng()只产生在服务器上的黑色图像

编程入门 行业动态 更新时间:2024-10-22 16:22:27
本文介绍了PHP imagepng()只产生在服务器上的黑色图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我是动态生成从用户上传的声音文件的波形图像,利用我已经基于一个脚本:的 andrewfreiday/2010/04/29/generating-mp3-waveforms-with-php/

I am dynamically generating a waveform image from a user-uploaded sound file, using a script I've based on: andrewfreiday/2010/04/29/generating-mp3-waveforms-with-php/

该脚本工作正常在我的开发环境的Windows 7的Apache2,PHP 5。但是,当我把它放在我的服务器Ubuntu Linux操作系统,Apache2的PHP 5,imagepng()输出一个黑盒子。

The script works fine on my dev environment Windows 7, Apache2, PHP 5. But when I put it on my server Ubuntu Linux, Apache2 PHP 5, imagepng() outputs a black box.

我已经研究过类似的问题,比如这是为什么创建黑色图像?并已确保我imagealphablending()和imagesavealpha()正在使用中描述的方式。但仍没有运气。我检查了文件夹的权限,并确认LAME可以写入正确的文件夹而不发出一个错误。

I've looked into similar problems, such as Why is this creating a black image? and have made sure that my imagealphablending() and imagesavealpha() are being used the way described. But still no luck. I've checked folder permissions and confirmed that LAME can write into the proper folder without throwing an error.

我也试着简单地将背景色设置为相同的颜色作为我的网页backgground,因为透明度是一个不错的,而不是必需品。

I've also tried to simply set the background color to the same color as my pages backgground, as the transparency is a "nice to have," not a necessity.

总之,这里是我的输出图像的PHP:

Anyway, here is the PHP that outputs my image:

// 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调用它:

And this is the Javascript that calls it:

//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)} }); },

我一直在敲我的头这两天,任何帮助将AP preciated。

I've been banging my head against this for two days now, any help will be appreciated.

推荐答案

尝试添加

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

$rimg = imagecreatetruecolor($width, $height); imagealphablending($rimg, false); imagesavealpha($rimg, true);

整体的一部分:

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

更多推荐

PHP imagepng()只产生在服务器上的黑色图像

本文发布于:2023-11-01 02:19:22,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1547966.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:器上   图像   黑色   PHP   imagepng

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!