<?php
/**
* 图片解码类
*/
class decryImg {
protected $imgPath; //图片路径
protected $dataArray; //
protected $imageSize; //图片尺寸
protected $data; //结果
protected $keys; //解码对应关系
protected $imgInfo; //对图片规格的描述
public function __construct($imgInfo) {
$this->keys = array(
'0' => '0000000000000000001111000110011001100110011001100110011001100110011001100011110000000000',
'1' => '0000000000000000000110000011100000011000000110000001100000011000000110000011110000000000',
'2' => '0000000000000000001111000110011000000110000011000001100000110000011000000111111000000000',
'3' => '0000000000000000001111000110011000000110000111000000011000000110011001100011110000000000',
'4' => '0000000000000000000001000000110000011100001011000100110001111110000011000000110000000000',
'5' => '0000000000000000001111100011000000110000001111000000011000000110011001100011110000000000',
'6' => '0000000000000000000111000011000001100000011111000110011001100110011001100011110000000000',
'7' => '0000000000000000011111100000011000001100000011000001100000011000001100000011000000000000',
'8' => '0000000000000000001111000110011001100110001111000110011001100110011001100011110000000000',
'9' => '0000000000000000001111000110011001100110011001100011111000000110000011000011100000000000',
'.' => '0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'
);
$this->imgInfo = $imgInfo;
}
/**
* 获得图片的解码
* @return 解码结果
*/
public function getNumFromImgUrl($url) {
$this->imgPath = $url;
$this->_getHec();
return $this->_run();
}
/**
* 将图片转成成数组
*/
private function _getHec() {
$res = imagecreatefrompng($this->imgPath);
$size = getimagesize($this->imgPath);
$data = array();
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->dataArray = $data;
$this->imageSize = $size;
}
/**
* 开始处理
* @return 解码结果
*/
private function _run() {
$result = "";
$data = array();
$numCount; //字符数目
$DotPlus = 0; //标记是否出现了小数点
switch ($this->imageSize[0]) {
case 45:
$numCount = 4;
break;
case 55:
$numCount = 5;
break;
case 60:
$numCount = 6;
break;
case 70:
$numCount = 7;
break;
case 80:
$numCount = 8;
break;
default :
$numCount = 9;
}
for ($i = 0; $i < $numCount; ++$i) {
$x = ($i * ($this->imgInfo['wordWidth'] + $this->imgInfo['wordSpacing'])) + $this->imgInfo['offsetX'] + $DotPlus;
$y = $this->imgInfo['offsetY'];
array_push($data, '');
for ($h = $y; $h < ($this->imgInfo['offsetY'] + $this->imgInfo['wordHeight']); ++$h) {
for ($w = $x; $w < ($x + $this->imgInfo['wordWidth']); ++$w) {
$data[$i] .=$this->dataArray[$h][$w];
}
}
if (!in_array($data[$i], $this->keys)) {
$DotPlus = 4 - $this->imgInfo['wordWidth'];
$data[$i] = $this->keys['.'];
}
}
$num = 0;
// 进行关键字匹配
foreach ($data as $numKey => $numString) {
foreach ($this->keys as $key => $value) {
if ($value === $numString) {
$num = $key;
break;
}
}
$result.=$num;
}
$this->data = $result;
return $result;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
javasript为主,php为代理实现电商综合搜索
共22个文件
js:8个
gif:3个
php:2个
4星 · 超过85%的资源 需积分: 9 18 下载量 30 浏览量
2013-06-03
10:13:17
上传
评论
收藏 103KB ZIP 举报
温馨提示
javasript为主,php为代理实现电商综合搜索(支持淘宝、京东、拍拍) 一个小项目,实现对淘宝、京东、拍拍进行爬取和展现。 京东价格是图片,里面有个图片解析的过程。 练手而已,不做任何用途,欢迎指教
资源推荐
资源详情
资源评论
收起资源包目录
multiGood.zip (22个子文件)
multiGood
css
style.css 3KB
img
1.jpg 12KB
loading.gif 4KB
agent
decryImg.class.php 3KB
agent.php 1KB
index.html 3KB
js
jquery.js 247KB
agentTool.js 2KB
paiPai.js 2KB
blank
cuzn_blank.css 887B
shadow.gif 1KB
cuzn_blank.js 6KB
shadow.png 933B
title_bg.gif 165B
taoBao.js 3KB
search.js 6KB
siteParent.js 827B
jingDong.js 2KB
nbproject
private
private.xml 230B
private.properties 107B
project.xml 322B
project.properties 140B
共 22 条
- 1
资源评论
- u0109216472013-06-03很好!自己学习的时候参考一下
- u0109018242013-06-03下下来后发现没什么用处,不过还是谢谢LZ了。
刀剑分天下
- 粉丝: 49
- 资源: 101
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功