Created
November 16, 2017 07:48
-
-
Save imdong/042eb3de053529082c1adfc7eb22cb81 to your computer and use it in GitHub Desktop.
dm_CodesRec
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// 定义文件名 | |
$imgSrc = './1.jpg'; | |
// 获取图片尺寸信息 | |
$imgSize = getimagesize($imgSrc); | |
// 创建图片对象 | |
$imgObj = imagecreatefromjpeg($imgSrc); | |
// 创建单色图片 | |
$img_R = imagecreate($imgSize['0'], $imgSize['1']); | |
$img_G = imagecreate($imgSize['0'], $imgSize['1']); | |
$img_B = imagecreate($imgSize['0'], $imgSize['1']); | |
// 设置背景色 | |
imagecolorallocate($img_R, 255, 0, 0); | |
// 设置黑白色 | |
$white = imagecolorallocate($img_R, 0, 0, 0); | |
$black = imagecolorallocate($img_R, 255, 255, 255); | |
for ($y=0; $y < $imgSize['1']; $y++) { | |
for ($x=0; $x < $imgSize['0']; $x++) { | |
// 取某点颜色 | |
$img_col = imagecolorat($imgObj, $x, $y); | |
$img_colR = ( $img_col >> 16 ) & 0xFF ; | |
$img_colG = ( $img_col >> 8 ) & 0xFF ; | |
$img_colB = $img_col & 0xFF ; | |
// 画点颜色 | |
if($img_colR > 128 && $img_colG > 128 && $img_colB > 128){ | |
echo '0'; | |
imagesetpixel($img_R, $x, $y, $black); | |
}else{ | |
echo '1'; | |
imagesetpixel($img_R, $x, $y, $white); | |
} | |
// imagesetpixel($img_G, $x, $y, imagecolorallocate($img_G, 0, hexdec($img_cols['1']), 0)); | |
// imagesetpixel($img_B, $x, $y, imagecolorallocate($img_B, 0, 0, hexdec($img_cols['2']))); | |
} | |
echo "\n"; | |
} | |
// 保存灰度图 | |
//image2wbmp(image)($img_R) | |
imagejpeg($img_R, $imgSrc . '_R.bmp'); | |
// imagejpeg($img_G, $imgSrc . '_G.bmp'); | |
// imagejpeg($img_B, $imgSrc . '_B.bmp'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// 获取字库说明 | |
if(empty($_GET['str'])){ | |
$dm_dicStr = "60380F0360CC318C1F01C0$2$0.0.47$13"; | |
}else{ | |
$dm_dicStr = $_GET['str']; | |
} | |
$dicListStr = file_get_contents('a1.txt'); | |
$dicListStr = iconv('gb2312', 'utf-8', $dicListStr); | |
$dicList = explode("\r\n", $dicListStr); | |
header("Content-Type: text/html; charset=utf-8"); | |
foreach ($dicList as $dicStr) { | |
if(strlen($dicStr) > 0) { | |
echo "{$dicStr}\n"; | |
dmDicResolve($dicStr); | |
} | |
} | |
/** | |
* 解析大漠字库记录 | |
* 参数一 大漠字库 单条记录 | |
* | |
*/ | |
function dmDicResolve($DicStr){ | |
// 分解字库关系 | |
$dm_dicInfo = explode('$', $DicStr); | |
/* 字段分析说明 008070F26203C8070020$A$0.0.21$9 | |
* 008070F26203C8070020 二值化点阵描述 | |
* A 定义名称 | |
* 0.0.21 未知 . 未知 . 黑点数 | |
* 9 字符实际高度 | |
*/ | |
//**** 将十六进制转换为二进制点阵字 ****// | |
$dm_dicStr = $dm_dicInfo['0']; // 取出十六进制描述 | |
// 逐字转成二进制 | |
$dm_dicStrArr = str_split($dm_dicStr, 1); | |
$dm_dicStr = ''; | |
foreach ($dm_dicStrArr as $dm_dicV) { | |
$dm_dicT = base_convert($dm_dicV, 16, 2); // 转换为二进制 | |
$dm_dicStr.= str_pad($dm_dicT, 4, '0', STR_PAD_LEFT); // 前面用0补齐4位 | |
} | |
// 获取字阵宽度 | |
$dm_StrWidth = ceil(strlen($dm_dicStr) / 11) - 1; | |
// 转换为点阵 | |
$dm_dicStrArr = str_split($dm_dicStr, 11); | |
// 判断最后一个是否需要删除 | |
if(strlen($dm_dicStrArr[count($dm_dicStrArr)-1]) < 11){ | |
array_pop($dm_dicStrArr); | |
} | |
// 颠倒点阵 | |
$a = 0; $b = 0; | |
for ($y=0; $y < 11; $y++) { | |
for ($x=0; $x < count($dm_dicStrArr); $x++) { | |
if($dm_dicStrArr[$x][$y] == '0'){ | |
$a++; | |
echo "□"; | |
}else{ | |
$b++; | |
echo "■"; | |
} | |
} | |
echo "\n"; | |
} | |
echo "白: {$a}, 黑:{$b}\n==========\n"; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment