Board logo

标题: 控制台印章制作工具stamp.exe [打印本页]

作者: happy886rr    时间: 2017-2-5 23:43     标题: 控制台印章制作工具stamp.exe

本帖最后由 happy886rr 于 2017-2-5 23:49 编辑

STAMP.EXE批之印。开源版采取免费发行策略,且只提供部分功能。更多高级功能比如存为透明png、高精度走样、图形水印、电子防伪、定制印框、定做字体、图形GUI界面、数论变换插值等请发短消息详谈。
开源版下载地址http://qiannao.com/file/wodewangpan798/68793990/

测试样张:




摘要:
=============================================================================
控制台印章绘制工具,多达12种自由参数,完美诠释“印”的艺术。几行命令即可让你
绘出专属印章。
=============================================================================

用法:
-----------------------------------------------------------------------------
stamp [options]   {arguments}...
-----------------------------------------------------------------------------
      /set-center [x] [y]                                       设置印章中心
      /set-font   [with]   [high]   [thin]   [color] [fonts]    设置印章字体
      /img-frame  [with/2] [high/2] [thin]   [color] [style]    设置印章框体
      /img-text   [string] [angle]  [dangle] [r]     [style]    设置印章正文
-----------------------------------------------------------------------------

示例:
-----------------------------------------------------------------------------
绘制古代方刻章
stamp /SET-CENTER 300 200 /IMG-FRAME 200 200 10 12 8
-----------------------------------------------------------------------------

备注:

/img-frame 中的[style]取值 (-1) ~ 8 代表10种不同框体
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/img-text  中的[style]取值 (-2) ~ 1 代表 4种不同文形
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/img-text  中的[angle]字体初始相位角、[dangle]字体间隔角、[r]字体环绕半径
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
十六色系:[color]取值 0 ~ 15
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0      {  0,  0,  0,RGB(  0,  0,  0)}, //黑色
1      {  0,  0,255,RGB(  0,  0,255)}, //蓝色
2      {  0,255,  0,RGB(  0,255,  0)}, //绿色
3      {  0,255,255,RGB(  0,255,255)}, //青色
4      {255,  0,  0,RGB(255,  0,  0)}, //红色
5      {238,130,238,RGB(238,130,238)}, //紫兰
6      {165, 42, 42,RGB(165, 42, 42)}, //棕色
7      {211,211,211,RGB(211,211,211)}, //浅灰
8      {169,169,169,RGB(169,169,169)}, //深灰
9      {173,216,230,RGB(173,216,230)}, //淡蓝
10      {144,238,144,RGB(144,238,144)}, //浅绿
11      {224,255,255,RGB(224,255,255)}, //淡青
12      {248, 29, 56,RGB(248, 29, 56)}, //亮红
13      {255,  0,255,RGB(255,  0,255)}, //洋紫
14      {255,255,  0,RGB(255,255,  0)}, //黄色
15      {255,255,255,RGB(255,255,255)}  //白色
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2017-02-05


原创代码:
  1. /*
  2. CONSOLE STAMP TOOL, COPYRIGHT@2017~2019 BY HAPPY, VERSION 1.0
  3. STAMP.EXE
  4. */
  5. #include <stdio.h>
  6. #include <Windows.h>
  7. //定义圆周率
  8. #define FPU_PI 3.1415926535897932
  9. //申明函数
  10. HWND WINAPI GetConsoleWindow();
  11. //定义帮助说明
  12. #define HELP_INFORMATION "\
  13. -----------------------------------------------------------------\n\
  14. CONSOLE STAMP TOOL, COPYRIGHT@2017~2019 BY HAPPY, VERSION 1.0\n\
  15. -----------------------------------------------------------------\n\
  16. stamp [options]   {arguments}...\n\
  17. -----------------------------------------------------------------\n\
  18.       /set-center [x] [y]\n\
  19.       /set-font   [with/2] [high/2] [thin]   [color] [fonts]\n\
  20.       /img-frame  [with/2] [high/2] [thin]   [color] [style]\n\
  21.       /img-text   [string] [angle]  [dangle] [r]     [style]\n\
  22. -----------------------------------------------------------------\n\
  23. 2017-02-03"
  24. /***************定义全局变量*************/
  25. //定义字体属性
  26. static char* pFONT="@system";
  27. static int   CENTERX=0, CENTERY=0, pWITH=30, pHEIGHT=100, pTHIN=10, pCOLOR=12;
  28. //定义关键词目
  29. #define            SENSITIVE_NUM   7
  30. static const char* SENSITIVE_WORDS[]={"/SET-CENTER", "/SET-FONT", "/IMG-FRAME", "/IMG-TEXT", "/HELP", "/H", "/?"};
  31. static const char  SENSITIVE_ARGVS[]={2,5,5,5,0,0,0};
  32. //定义十六色系
  33. static const COLORREF PRGB[16]=
  34. {
  35. RGB(  0,  0,  0), //黑色
  36. RGB(  0,  0,255), //蓝色
  37. RGB(  0,255,  0), //绿色
  38. RGB(  0,255,255), //青色
  39. RGB(255,  0,  0), //红色
  40. RGB(238,130,238), //紫兰
  41. RGB(165, 42, 42), //棕色
  42. RGB(211,211,211), //浅灰
  43. RGB(169,169,169), //深灰
  44. RGB(173,216,230), //淡蓝
  45. RGB(144,238,144), //浅绿
  46. RGB(224,255,255), //淡青
  47. RGB(248, 29, 56), //亮红
  48. RGB(255,  0,255), //洋紫
  49. RGB(255,255,  0), //黄色
  50. RGB(255,255,255)  //白色
  51. };
  52. /***************功能函数群***************/
  53. //度转弧度
  54. double FPU_torad(double x)
  55. {
  56. return x*FPU_PI/180;
  57. }
  58. //正弦函数
  59. double FPU_sin(double x)
  60. {
  61. double FPU_RET;
  62. __asm__
  63. (
  64. "fsin\n"
  65. : "=t" (FPU_RET)
  66. : "0"  (x)
  67. );
  68. return FPU_RET;
  69. }
  70. //余弦函数
  71. double FPU_cos(double x)
  72. {
  73. double FPU_RET;
  74. __asm__
  75. (
  76. "fcos\n"
  77. : "=t" (FPU_RET)
  78. : "0"  (x)
  79. );
  80. return FPU_RET;
  81. }
  82. //开方函数
  83. double FPU_sqrt(double x)
  84. {
  85. double FPU_RET;
  86. __asm__
  87. (
  88. "fsqrt\n"
  89. : "=t" (FPU_RET)
  90. : "0"  (x)
  91. );
  92. return FPU_RET;
  93. }
  94. //识别关键词
  95. int itifyWORDS(const char* strARGV)
  96. {
  97. int i, SN;
  98. for(SN=0; SN<SENSITIVE_NUM; SN++){
  99. char *op=(char*)strARGV, *kp=(char*)SENSITIVE_WORDS[SN];
  100. while(*kp!='\0'){
  101. if( (('a'<= *op && *op<='z')?*op-32:*op) != (('a'<= *kp && *kp<='z')?*kp-32:*kp) ){break;}
  102. op++;kp++;
  103. }
  104. if( (*kp=='\0') && (*op==' '||*op=='\t'||*op=='\r'||*op=='\n'||*op=='\0') ){return SN;}
  105. }
  106. return -1;
  107. }
  108. //绘制印框
  109. void drawFRAME(HDC hDC, int frameWITH_HALF, int frameHEIGHT_HALF, int frameTHIN, int frameCOLOR, int shapeMODE)
  110. {
  111. HPEN hPEN=CreatePen(PS_SOLID, frameTHIN, PRGB[frameCOLOR]);
  112. SelectObject(hDC, hPEN);
  113. //建空画刷
  114. HBRUSH mBRUSH=(shapeMODE==-1||shapeMODE==2)?CreateSolidBrush(PRGB[frameCOLOR]):GetStockObject(NULL_BRUSH);
  115. SelectObject(hDC, mBRUSH);
  116. //背景透明
  117. SetBkMode(hDC,TRANSPARENT);
  118. if      (shapeMODE==-1){
  119. //绘制实心椭圆
  120. Ellipse(  hDC, CENTERX-frameWITH_HALF,CENTERY-frameHEIGHT_HALF,CENTERX+frameWITH_HALF,CENTERY+frameHEIGHT_HALF);
  121. }else if(shapeMODE==0){
  122. //绘制椭圆框体
  123. Ellipse(  hDC, CENTERX-frameWITH_HALF,CENTERY-frameHEIGHT_HALF,CENTERX+frameWITH_HALF,CENTERY+frameHEIGHT_HALF);
  124. }else if(shapeMODE==1||shapeMODE==2){
  125. //绘制矩形框体
  126. Rectangle(hDC, CENTERX-frameWITH_HALF,CENTERY-frameHEIGHT_HALF,CENTERX+frameWITH_HALF,CENTERY+frameHEIGHT_HALF);
  127. }else if(3<=shapeMODE &&shapeMODE<=8){
  128. //绘制十字矩形
  129. Rectangle(hDC, CENTERX-frameWITH_HALF,CENTERY-frameHEIGHT_HALF,CENTERX               ,CENTERY+frameHEIGHT_HALF);
  130. Rectangle(hDC, CENTERX               ,CENTERY-frameHEIGHT_HALF,CENTERX+frameWITH_HALF,CENTERY+frameHEIGHT_HALF);
  131. //设置实(空)心画刷
  132. mBRUSH=(shapeMODE==7||shapeMODE==8)?CreateSolidBrush(PRGB[frameCOLOR]):GetStockObject(NULL_BRUSH);
  133. SelectObject(hDC, mBRUSH);
  134. if(shapeMODE>3){
  135. if(shapeMODE==4||shapeMODE==6||shapeMODE==7||shapeMODE==8){
  136. if      (shapeMODE==7){
  137. Rectangle(hDC, CENTERX-frameWITH_HALF,CENTERY,CENTERX,CENTERY+frameHEIGHT_HALF);
  138. }else if(shapeMODE==8){
  139. Rectangle(hDC, CENTERX-frameWITH_HALF,CENTERY-frameHEIGHT_HALF,CENTERX-frameTHIN/2,CENTERY-frameTHIN/2);
  140. }else                 {
  141. Rectangle(hDC, CENTERX-frameWITH_HALF,CENTERY-frameHEIGHT_HALF,CENTERX,CENTERY);
  142. }
  143. }
  144. if(shapeMODE==5||shapeMODE==6||shapeMODE==8){
  145. if(shapeMODE==8){
  146. Rectangle(hDC, CENTERX+frameTHIN/2,CENTERY+frameTHIN/2,CENTERX+frameWITH_HALF,CENTERY+frameHEIGHT_HALF);
  147. }else{
  148. Rectangle(hDC, CENTERX,CENTERY,CENTERX+frameWITH_HALF,CENTERY+frameHEIGHT_HALF);
  149. }
  150. }
  151. }
  152. }
  153. //清除对象
  154. DeleteObject(hPEN);
  155. DeleteObject(mBRUSH);
  156. return;
  157. }
  158. //绘制印文(心符)
  159. void drawTEXT(HDC hDC, char* pSTRING, int pANGLE, int pDANGLE, int RADIUS, int shapeMODE)
  160. {
  161. LOGFONTA fontSRC={
  162. pHEIGHT,            //字体高度
  163. pWITH,              //字体宽度
  164. pANGLE*10,          //显示角度(3600进制)
  165. 0,                  //nOrientation
  166. pTHIN,              //字体磅数
  167. FALSE,              //非倾斜体
  168. FALSE,              //无下划线
  169. FALSE,              //无删除线
  170. DEFAULT_CHARSET,    //默认字集
  171. OUT_DEFAULT_PRECIS, //输出精度
  172. CLIP_DEFAULT_PRECIS,//裁减精度
  173. DEFAULT_QUALITY,    //nQuality
  174. DEFAULT_PITCH,      //nPitchAndFamily
  175. ""                  //字体
  176. };
  177. //临时辅助指针
  178. LOGFONTA* pSRC=&fontSRC;
  179. //赋值字体名称
  180. strcpy(pSRC->lfFaceName, pFONT);
  181. //创建属性字体
  182. HFONT  hFONT=CreateFontIndirectA(pSRC);
  183. //选择字体属性
  184. SelectObject(hDC, hFONT);
  185. //设置背景透明
  186. SetBkMode(hDC,TRANSPARENT);
  187. //设置字体颜色
  188. SetTextColor(hDC, PRGB[pCOLOR]);
  189. if(shapeMODE==-2 ||shapeMODE==-1 ||shapeMODE==0 ||shapeMODE==1){
  190. //绘制环形文本
  191. byte  *pTEXT=(byte*)pSTRING, *p=(byte*)calloc(3, sizeof(byte));
  192. for(; *pTEXT!='\0'; pTEXT++,pANGLE+=pDANGLE){
  193. p[0]=*pTEXT, p[1]=((*pTEXT)<0x80)?0:*(++pTEXT);
  194. pSRC->lfEscapement=(shapeMODE==0) ?pANGLE*10-900 :(shapeMODE==-1) ?pANGLE*10+900:0;
  195. hFONT=CreateFontIndirectA(pSRC);
  196. SelectObject(hDC, hFONT);
  197. if(shapeMODE==1){
  198. TextOutA(hDC, CENTERX+RADIUS*FPU_cos(FPU_torad(pANGLE))-pWITH*FPU_sqrt(2)*FPU_cos(FPU_torad(pSRC->lfEscapement/10)-FPU_PI/4), CENTERY-RADIUS*FPU_sin(FPU_torad(pANGLE))+pWITH*FPU_sqrt(2)*FPU_sin(FPU_torad(pSRC->lfEscapement/10)-FPU_PI/4), pSTRING, lstrlenA(pSTRING));
  199. DeleteObject(hFONT);
  200. return;
  201. }
  202. TextOutA(hDC, CENTERX+RADIUS*FPU_cos(FPU_torad(pANGLE))-pWITH*FPU_sqrt(2)*FPU_cos(FPU_torad(pSRC->lfEscapement/10)-FPU_PI/4), CENTERY-RADIUS*FPU_sin(FPU_torad(pANGLE))+pWITH*FPU_sqrt(2)*FPU_sin(FPU_torad(pSRC->lfEscapement/10)-FPU_PI/4), (char*)p, lstrlenA((char*)p));
  203. }
  204. }
  205. //清理对象
  206. DeleteObject(hFONT);
  207. return;
  208. }
  209. //开关解析函数
  210. void OptRE(HDC  hDC, int argc, char** argv)
  211. {
  212. //计算有效参数数目
  213. int oargc=argc-1, anum;
  214. if(oargc==0){
  215. //无参数,则抛出使用说明
  216. fputs(HELP_INFORMATION, stderr);
  217. exit(1);
  218. }
  219. //参数接收针
  220. char** oargv=argv;
  221. //参数累加器
  222. int i=0;
  223. //开启主循环
  224. while((++i)<=oargc){
  225. int SN=itifyWORDS(argv[i]);
  226. if(SN!=-1){
  227. if(i+SENSITIVE_ARGVS[SN]>oargc){
  228. //缺少必要参数
  229. fprintf(stderr, "The option '%s' needs %d parameters\n", argv[i], SENSITIVE_ARGVS[SN]);
  230. exit(1);
  231. }
  232. for(anum=1; anum<=SENSITIVE_ARGVS[SN]; anum++){
  233. if(oargv[i+anum][0]==SENSITIVE_WORDS[0][0]){
  234. //缺少必要参数
  235. fprintf(stderr, "Only %d parameters, the option '%s' needs %d parameters\n", anum-1, argv[i], SENSITIVE_ARGVS[SN]);
  236. exit(1);
  237. }
  238. }
  239. //执行开关命令
  240. switch(SN)
  241. {
  242. case 0:
  243. //set-center
  244. CENTERX=atoi(argv[i+1]), CENTERY=atoi(argv[i+2]);
  245. break;
  246. case 1:
  247. //set-font
  248. pWITH=atoi(argv[i+1]), pHEIGHT=atoi(argv[i+2]), pTHIN=atoi(argv[i+3]), pCOLOR=atoi(argv[i+4]), pFONT=argv[i+5];
  249. break;
  250. case 2:
  251. //img-frame
  252. drawFRAME(hDC, atoi(argv[i+1]), atoi(argv[i+2]), atoi(argv[i+3]), atoi(argv[i+4]), atoi(argv[i+5]));
  253. break;
  254. case 3:
  255. //img-text
  256. drawTEXT( hDC, argv[i+1], atoi(argv[i+2]), atoi(argv[i+3]), atoi(argv[i+4]), atoi(argv[i+5]));
  257. break;
  258. default:
  259. //使用说明
  260. fputs(HELP_INFORMATION, stderr);
  261. exit(1);
  262. }
  263. i+=SENSITIVE_ARGVS[SN];
  264. //无法识别的参数
  265. }else{
  266. fprintf(stderr, "An error occurred near '%s'\n", argv[i]);
  267. exit(1);
  268. }
  269. }
  270. }
  271. /*************MAIN主函数入口*************/
  272. int main(int argc, char** argv)
  273. {
  274. //获取CMD窗口句柄
  275. HWND hCMD=GetConsoleWindow();
  276. HDC  hDC =GetDC(hCMD);
  277. //解析开关
  278. OptRE(hDC, argc, argv);
  279. //释放DC兼顾刷新
  280. ReleaseDC(hCMD, hDC);
  281. DeleteDC(hDC);
  282. return 0;
  283. }
复制代码
批处理调用演示
  1. @echo off
  2. ::***************************************************************************
  3. title 批之印模板二
  4. mode con cols=120 lines=35
  5. for /f "tokens=1-10" %%a in ('more +12 "%~f0"') do (
  6. stamp /SET-CENTER %%a %%b /IMG-FRAME 200 200 10 %%j 0 /IMG-FRAME 190 190 3 %%j 0  /SET-FONT %%i 100 10 %%j %%c /IMG-TEXT %%d 0 0 0 1 /SET-FONT 27 100 600 %%j %%c /IMG-TEXT %%e 203 -32 136 %%h /SET-FONT 9 22 600 %%j %%c /IMG-TEXT %%f 231 0 112 1 /SET-FONT 7 20 600 %%j %%c /IMG-TEXT %%g -15 -5 180  0
  7. )
  8. pause>nul
  9. exit /b
  10. ::***************************************************************************
  11. 500 200 宋体 ★ 北京圣天香有限公司 中华人民共和国经贸 BJLUNUAPICHTANZHULIZHNZHANG   0 50 4
  12. 230 260 宋体 ★ 山东维拉雅服饰     中华人民共和国经贸 SDYANJIUUEYIWAHUANNSHUXUANZZHANG 0 50 13
  13. 500 380 宋体 ★ 阿里巴巴集团专章   中华人民共和国经贸 ALBBNUAPICHTANZHULIZHNZHANG   0 50 14
复制代码





欢迎光临 批处理之家 (http://bbs.bathome.net/) Powered by Discuz! 7.2