(编辑:jimmy 日期: 2024/11/18 浏览:2)
本文实例讲述了php实现将wav文件转换成图像文件并在页面中显示的方法。分享给大家供大家参考。具体分析如下:
需求:将wav文件转换成png文件并且显示出来。
Wav_To_Png.php:
<"Content-type: image/png"); $im = imagecreate($s / $w, $h * $c * 2); imagecolorallocate($im, 0xff, 0xff, 0xff); // white bg $color = imagecolorallocate($im, 0, 0, 255); // black imagestring($im, 5, 5, 5, $str, $color); $x=0; $y = array(); $yn = array(); for($i = 0; $i < $c; $i++) $y[$i] = $h * $i + $h; $n = $l * $w; while(1) { if($s == 0) break; if($s < $n) $n = $s; $samples = fread($fp, 1000 * $n); if($samples === FALSE) break; $packed = unpack("s*", $samples); foreach($packed as $k=>$v) { $cnt = ($k-1) % ($w * $l) ; if( $cnt > $c - 1) continue; $yn[$cnt] = $h * $cnt + $h - $v / $f; imageline($im, $x, $y[$cnt], $x+1, $yn[$cnt], $color); $y[$cnt] = $yn[$cnt]; $x++; } $s -= $n; } imagepng($im); imagedestroy($im); } wav_graph('GetWave.wav'); "//img.jbzj.com/file_images/article/201504/2015421162550230.jpg" alt="" />希望本文所述对大家的php程序设计有所帮助。