当前位置:Gxlcms > PHP教程 > 网上的一段代码错哪了

网上的一段代码错哪了

时间:2021-07-01 10:21:17 帮助过:19人阅读

网上的一段代码哪里错了?
/**
* 电话号码识别.
* @author by zsc for 2010.03.24
*/

class gjPhone{
protected $imgPath;//图片路径
protected $imgSize;//图片大小
protected $hecData;//分离后数组
protected $horData;//横向整理的数据
protected $verData;//纵向整理的数据

function __construct($path){
$this->imgPath = $path;
}
/**
* 颜色分离转换...
*
* @param unknown_type $path
* @return unknown
*/
public function getHec()
{
$size = getimagesize($this->imgPath);
$res = imagecreatefrompng($this->imgPath);
for($i=0; $i < $size[1]; ++$i)
{
for($j=0; $j < $size[0]; ++$j)
{
$rgb = imagecolorat($res,$j,$i);
$rgbarray = imagecolorsforindex($res, $rgb);
if($rgbarray['red'] < 125 || $rgbarray['green']<125
|| $rgbarray['blue'] < 125)
{
$data[$i][$j]=1;
}else{
$data[$i][$j]=0;
}
}
}
$this->imgSize = $size;
$this->hecData = $data;
}
/**
* 颜色分离后的数据横向整理...
*
* @return unknown
*/
public function magHorData()
{

$data = $this->hecData;
$size = $this->imgSize;
$z = 0;
for($i=0; $i<$size[1]; ++$i)
{
if(in_array('1',$data[$i])){
$z++;
for($j=0; $j<$size[0]; ++$j)
{
if($data[$i][$j] == '1'){
$newdata[$z][$j] = 1;
}else{
$newdata[$z][$j] = 0;
}
}
}

}
return $this->horData = $newdata;
}
/**
* 整理纵向数据...
*
* @return unknown
*/
public function magVerData($newdata){
for ($i=0;$i<132;++$i){
for($j=1;$j<13;++$j){
$ndata[$i][$j] = $newdata[$j][$i];
}
}


$sum = count($ndata);
$c = 0;
for ($a=0;$a<$sum;$a++){
$value = $ndata[$a];
if(in_array(1,$value)){

人气教程排行