Board logo

标题: 拼图脚本工具 jimg [打印本页]

作者: happy886rr    时间: 2017-9-9 21:48     标题: 拼图脚本工具 jimg

Jimg是一款控制台下拼图脚本工具,类似gawk的性质,但处理的是图片并非文本。可以将拼接好的图片出书为各种格式。可以绘制图片的切片,透明色、图片旋转 等多种属性。同时可以很好的继承批处理中的环境变量。
可以在脚本中使用%变量名%之类的扩展语法。语法完全模仿cmd,易于掌握。功能妙用,请自己体验,一般很少能找到这类批处理下替代ps拼图功能的第三方。对不善于编译的坛友,提供一个7KB附件下载:
http://bcn.bathome.net/s/tool/index.html?key=Jimg

下面是一个jimg格式的脚本示例:(警告:脚本的文件编码必须存为UNICODE)
  1. REM 脚本演示:
  2. :MAIN1
  3. ECHO TEST1.JPG -C 0,0 -S %VAR1%,%VAR2%,300,100        
  4. ECHO %ENV_FILE% -C 0,0 -S 0,100,0,0 -R 0,0,30
  5. ECHO TEST3.PNG -C 0,0 -S 0,300,0,0
  6. ECHO TEST4.JPG -C 0,0 -S 0,600,0,0 -R 300,0,60
  7. ECHO TEST5.JPG -C 0,0 -S 0,900,0,0 -R 0,200,130
  8. EXIT
  9. :MAIN2
  10. ECHO TEST2.JPG -C 0,0 -S 0,0,0,0               
  11. ECHO TEST2.JPG -C 0,0 -S 0,100,0,0 -R 0,0,30
  12. ECHO TEST3.PNG -C 0,0 -S 0,300,0,0 -T 100,255,255,127
  13. EXIT
复制代码
就是这样便捷,将图片echo到图形文件里。

JIMG.EXE (CONSOLE IMAGE JOIN TOOL, COPYRIGHT@2017~2019 BY HAPPY, VERSION 1.0)
摘要:
===============================================================
JIMG.EXE,是一款奇异的命令行拼图工具。同时也支持其他图片格式的转换、裁剪、透明色处理等操作。
===============================================================

版本:
VERSION 1.0

用法:
-------------------------------------------------------------------------
jimg   [输入文件]
    -o [输出文件]
    -s [[显示宽度],[显示高度]]
    -b [[A],[R],[G],[B]]
    -j [要跳到的标签]

脚本中的拼图用法
      [输入文件]
    -c[[x],[y],[width],[height]]
    -s[[x],[y],[width],[height]]
    -t[[A],[R],[G],[B]]
-------------------------------------------------------------------------

主程序调用示例:
-------------------------------------------------------------------------
REM 运行test.ji绘图输出1024*7200尺寸的图片1024,7200
jimg test.ji -otest.png -s1024,7200
...
-------------------------------------------------------------------------

英译:
-------------------------------------------------------------------------
Jimg v1.0 - Console image join tool - Copyright (C) 2017-2019 by Happy
Usage:
    jimg [input_script] -o[output_image] -s[image_size] -b[image_background_color]

General options:
    -o[path]                      Output image file
    -s[[width],[height]]          Output image size
    -b[[A],[R],[G],[B]]           Output image background color
    -j[jump_mark]                 Goto the jump mark of the input script
    -h                            Show help information

Script options:
    -c[[x],[y],[width],[height]]  Cut rect
    -s[[x],[y],[width],[height]]  Show rect
    -t[[A],[R],[G],[B]]           Transparent ARGB

Official website:
      http://www.bathome.net/thread-18888-8-8.html
-------------------------------------------------------------------------
SAT SEP 09 2017 10:28:16 GMT+0800


原创代码:
  1. /*
  2. CONSOLE IMAGE JOIN TOOL, JIMG.EXE COPYRIGHT(C)2017~2019 BY HAPPY, VERSION 1.0
  3. SAT SEP 09 2017 10:28:16 GMT+0800
  4. **************************************************************************
  5. g++ jimg.cpp -lgdiplus -lgdi32 -lole32 -municode -O2 -static REM For MINGW
  6. cl  jimg.cpp /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /MT    REM For VS
  7. **************************************************************************
  8. */
  9. #if !defined(_UNICODE) && !defined(UNICODE)
  10. #define _UNICODE USED
  11. #define  UNICODE USED
  12. #endif
  13. #include <stdio.h>
  14. #include <stdlib.h>
  15. #include <string.h>
  16. #include <windows.h>
  17. #include <ctype.h>
  18. #include <tchar.h>
  19. #if !defined(WIN32) && !defined(__WIN32__)
  20. #error Only run on windows system
  21. #endif
  22. #if defined(_MSC_VER)
  23. #include <Gdiplus.h>
  24. #pragma comment(lib, "Gdi32.lib")
  25. #pragma comment(lib, "Gdiplus.lib")
  26. #pragma comment(lib, "Ole32.lib")
  27. #pragma comment(lib, "Shell32.lib")
  28. #else
  29. #include <gdiplus\gdiplus.h>
  30. #endif
  31. // 使用GDI+命名空间
  32. using namespace Gdiplus;
  33. // 定义帮助说明
  34. #define HELP_INFORMATION _T("\
  35. Jimg v1.0 - Console image join tool - Copyright (C) 2017-2019 by Happy\n\
  36. Usage:\n\
  37.     jimg [input_script] -o[output_image] -s[image_size] -b[image_background_color]\n\
  38. \n\
  39. General options:\n\
  40.     -o[path]                      Output image file\n\
  41.     -s[[width],[height]]          Output image size\n\
  42.     -b[[A],[R],[G],[B]]           Output image background color\n\
  43.     -j[jump_mark]                 Goto the jump mark of the input script\n\
  44.     -h                            Show help information\n\
  45. \n\
  46. Script options:\n\
  47.     -c[[x],[y],[width],[height]]  Cut rect\n\
  48.     -s[[x],[y],[width],[height]]  Show rect\n\
  49.     -t[[A],[R],[G],[B]]           Transparent ARGB\n\
  50. \n\
  51. Official website:\n\
  52.       http://www.bathome.net/thread-18888-8-8.html\n\
  53. ")
  54. // 标准行长
  55. #define MAX_BUFF_SIZE 1024
  56. // 开关解析宏名
  57. #define _OPT_TEOF -1
  58. #define _OPT_TILL -2
  59. #define _OPT_TERR -3
  60. // 开关解析变量
  61. int OPTIND = 1, OPTOPT = 0, UNOPTIND = -1;
  62. TCHAR* OPTARG = NULL;
  63. #if defined(_UNICODE) || defined(UNICODE)
  64. #define TCHARFORMAT WCHAR
  65. #else
  66. #define TCHARFORMAT CHAR
  67. #endif
  68. // 判断字母小写
  69. #define ISLOWERLETTER(x) ((_T('a') <= (x)) && ((x) <= _T('z')))
  70. // 图片格式关键词
  71. static const TCHAR* IMAGE_TYPE[] = {_T("image/bmp"), _T("image/jpeg"), _T("image/gif"), _T("image/tiff"), _T("image/png"), NULL};
  72. static const TCHAR* IMAGE_SUFFIX[] = {_T(".bmp"), _T(".jpg"), _T(".gif"), _T(".tif"), _T(".png"), NULL};
  73. // 开关解析函数
  74. int _tgetopt(int nargc, TCHAR* nargv[], TCHAR* ostr)
  75. {
  76. static TCHAR* place = (TCHAR*)_T("");
  77. static TCHAR* lastostr = NULL;
  78. register TCHAR* oli;
  79. if(ostr != lastostr)
  80. {
  81. lastostr = ostr;
  82. place=(TCHAR*)_T("");
  83. }
  84. if(!*place)
  85. {
  86. if
  87. (
  88.     (OPTIND >= nargc)                          ||
  89.     (*(place=nargv[OPTIND]) != (TCHAR)_T('-')) ||
  90.     (!*(++place))
  91. )
  92. {
  93. if(*place != (TCHAR)_T('-') && OPTIND <nargc)
  94. {
  95. place = (TCHAR*)_T("");
  96. if(UNOPTIND == -1)
  97. {
  98. UNOPTIND = OPTIND++;
  99. return _OPT_TILL;
  100. }
  101. else
  102. {
  103. return _OPT_TERR;
  104. }
  105. }
  106. place = (TCHAR*)_T("");
  107. return _OPT_TEOF;
  108. }
  109. if (*place == (TCHAR)_T('-') && *(place+1) == (TCHAR)_T('\0'))
  110. {
  111. ++OPTIND;
  112. return _OPT_TEOF;
  113. }
  114. }
  115. if (
  116.     (OPTOPT=*place++) == (TCHAR)_T(':') ||
  117.     !(oli=(TCHAR*)_tcschr((TCHARFORMAT*)ostr, (TCHAR)OPTOPT))
  118. )
  119. {
  120. if(!*place)
  121. {
  122. ++OPTIND;
  123. }
  124. }
  125. if ((oli != NULL) && (*(++oli) != (TCHAR)_T(':')))
  126. {
  127. OPTARG=NULL;
  128. if(!*place)
  129. {
  130. ++OPTIND;
  131. }
  132. }
  133. else
  134. {
  135. if((*place != _T('\0')))
  136. {
  137. OPTARG = place;
  138. }
  139. else if(nargc <= ++OPTIND)
  140. {
  141. place = (TCHAR*)_T("");
  142. }
  143. else
  144. {
  145. OPTARG = nargv[OPTIND];
  146. }
  147. place = (TCHAR*)_T("");
  148. ++OPTIND;
  149. }
  150. if(*OPTARG == _T('-'))
  151. {
  152. OPTARG = NULL;
  153. }
  154. return OPTOPT;
  155. }
  156. // 关键词识别函数
  157. int IdentifyKey(TCHAR* inStr, TCHAR** inKeyWords)
  158. {
  159. if (inStr == NULL)
  160. {
  161. return -1;
  162. }
  163. int SN = 0;
  164. while(inKeyWords[SN] != NULL)
  165. {
  166. TCHAR *op=inStr, *kp=inKeyWords[SN];
  167. while(*kp != _T('\0'))
  168. {
  169. if(
  170.     ((ISLOWERLETTER(*op))?(*op-32):(*op)) != ((ISLOWERLETTER(*kp))?(*kp-32):(*kp))
  171. )
  172. {
  173. break;
  174. }
  175. op++;
  176. kp++;
  177. }
  178. if(*kp == _T('\0'))
  179. {
  180. if(*op == _T('\0'))
  181. {
  182. return SN;
  183. }
  184. }
  185. SN ++;
  186. }
  187. return -1;
  188. }
  189. // 获取编码器CLSID
  190. BOOL GetEncoderClsid(const WCHAR* format, CLSID* pClsid)
  191. {
  192. UINT j, n=0, s=0;
  193. ImageCodecInfo* pInfo=NULL;
  194. GetImageEncodersSize(&n, &s);
  195. if(s == 0)
  196. {
  197. return FALSE;
  198. }
  199. pInfo=(ImageCodecInfo*)(malloc(s));
  200. if(pInfo == NULL)
  201. {
  202. return FALSE;
  203. }
  204. GetImageEncoders(n, s, pInfo);
  205. for(j=0; j<n; j++)
  206. {
  207. if(wcscmp(pInfo[j].MimeType, format) == 0)
  208. {
  209. *pClsid = pInfo[j].Clsid;
  210. free(pInfo);
  211. return TRUE;
  212. }
  213. }
  214. free(pInfo);
  215. return FALSE;
  216. }
  217. // image拼接手函数
  218. int DrawImageFile(Graphics* pGraphics, TCHAR* inImageFile, int lineNumber, BOOL useTransparentColor, Color transparentColor, int cut_x,  int cut_y, int cutWidth, int cutHeight, int showX, int showY, int showWidth, int showHeight, REAL roteX, REAL roteY, REAL roteAngle)
  219. {
  220. // 读取gif文件数据
  221. Image* imageFile = Image::FromFile((WCHAR*)inImageFile);
  222. // 获取gif原始宽高
  223. UINT imageWidth = imageFile->GetWidth();
  224. UINT imageHeight = imageFile->GetHeight();
  225. // 判断文件读取失败
  226. if((imageWidth & imageHeight) == 0)
  227. {
  228. _ftprintf(stderr, _T("[%d]: Read image '%s' failed\n"), lineNumber, inImageFile);
  229. exit(1);
  230. }
  231. // 修正传递的参数
  232. if(cut_x < 0 || cut_x > imageWidth)
  233. {
  234. cut_x = 0;
  235. }
  236. if(cut_y < 0 || cut_y > imageHeight)
  237. {
  238. cut_y = 0;
  239. }
  240. if(cutWidth <= 0 || cutWidth > imageWidth)
  241. {
  242. cutWidth = imageWidth;
  243. }
  244. if(cutHeight <= 0 || cutHeight > imageHeight)
  245. {
  246. cutHeight = imageHeight;
  247. }
  248. if(showWidth <= 0)
  249. {
  250. showWidth = imageWidth;
  251. }
  252. if(showHeight <= 0)
  253. {
  254. showHeight = imageHeight;
  255. }
  256. if(showX < 0 || showX >= imageWidth)
  257. {
  258. showX = 0;
  259. }
  260. if(showY < 0 || showY >= imageHeight)
  261. {
  262. showY = 0;
  263. }
  264. // 设置ImageAttributes颜色属性
  265. ImageAttributes* pAttributes = new ImageAttributes();
  266. // 设置透明颜色高低色位
  267. if(useTransparentColor)
  268. {
  269. pAttributes->SetColorKey(transparentColor, transparentColor, ColorAdjustTypeBitmap);
  270. }
  271. // 设置每帧输出尺寸
  272. Rect* pRect = new Rect(showX, showY, showWidth, showHeight);
  273. // 旋转矩阵
  274. Matrix* pMatri = new Matrix();
  275. pMatri->Reset();
  276. pMatri->RotateAt(roteAngle, PointF(roteX, roteY));
  277. // 旋转画布
  278. pGraphics->SetTransform(pMatri);
  279. // 拼接位图
  280. pGraphics->DrawImage(imageFile, *pRect, cut_x, cut_y, cutWidth, cutHeight, UnitPixel, pAttributes);
  281. // 清理绘图工具
  282. delete imageFile;
  283. delete pAttributes;
  284. delete pMatri;
  285. delete pRect;
  286. return 0;
  287. }
  288. // 脚本命令行解析函数
  289. int ParseScript(int scriptArgc, TCHAR** scriptArgv, int lineNumber, Graphics* pGraphics)
  290. {
  291. // 初始化开关解析变量
  292. OPTIND = 0, OPTOPT = 0, UNOPTIND = -1;
  293. OPTARG = NULL;
  294. // 初始化传递参数
  295. int cut_rect[4] = {0};
  296. int show_rect[4] = {0};
  297. REAL rote_matri[3] = {0};
  298. // 启用透明色过滤ARGB
  299. BOOL useTransparentColor = FALSE;
  300. byte tRGB[4] = {0};
  301. // 脚本中的图像文件
  302. TCHAR* inImageFile = NULL;
  303. // 开关解析
  304. int K = _OPT_TEOF;
  305. while((K=_tgetopt(scriptArgc, scriptArgv, (TCHAR*)_T("c:s:t:C:S:T:"))) != _OPT_TEOF)
  306. {
  307. switch(K)
  308. {
  309. case _T('c'):
  310. case _T('C'):
  311. if(OPTARG == NULL)
  312. {
  313. _ftprintf(stderr, _T("[%d]: The switch '-c' needs a cut rect\n"), lineNumber);
  314. exit(1);
  315. }
  316. {
  317. TCHAR* pTcstr = _tcstok(OPTARG, _T(","));
  318. for(int i=0; i<4 && pTcstr; i++)
  319. {
  320. cut_rect[i] = _ttoi((TCHARFORMAT*)pTcstr);
  321. pTcstr = _tcstok(NULL, _T(","));
  322. }
  323. }
  324. break;
  325. case _T('s'):
  326. case _T('S'):
  327. if(OPTARG == NULL)
  328. {
  329. _ftprintf(stderr, _T("[%d]: The switch '-s' needs a image show rect\n"), lineNumber);
  330. exit(1);
  331. }
  332. {
  333. TCHAR* pTcstr = _tcstok(OPTARG, _T(","));
  334. for(int i=0; i<4 && pTcstr; i++)
  335. {
  336. show_rect[i] = _ttoi((TCHARFORMAT*)pTcstr);
  337. pTcstr = _tcstok(NULL, _T(","));
  338. }
  339. }
  340. break;
  341. case _T('t'):
  342. case _T('T'):
  343. if(OPTARG == NULL)
  344. {
  345. _ftprintf(stderr, _T("[%d]: The switch '-t' needs a transparent ARGB color like [[A],[R],[G],[B]]\n"), lineNumber);
  346. exit(1);
  347. }
  348. {
  349. TCHAR* pTcstr = _tcstok(OPTARG, _T(","));
  350. for(int i=0; i<4 && pTcstr; i++)
  351. {
  352. tRGB[i] = (byte)_ttoi((TCHARFORMAT*)pTcstr);
  353. pTcstr = _tcstok(NULL, _T(","));
  354. }
  355. useTransparentColor = TRUE;
  356. }
  357. break;
  358. case _T('r'):
  359. case _T('R'):
  360. if(OPTARG == NULL)
  361. {
  362. _ftprintf(stderr, _T("[%d]: The switch '-r' needs a rote matri like [[roteX],[roteY],[roteAngle]]\n"), lineNumber);
  363. exit(1);
  364. }
  365. {
  366. TCHAR* pTcstr = _tcstok(OPTARG, _T(","));
  367. for(int i=0; i<3 && pTcstr; i++)
  368. {
  369. rote_matri[i] = (REAL)_tcstod((TCHARFORMAT*)pTcstr, NULL);
  370. pTcstr = _tcstok(NULL, _T(","));
  371. }
  372. }
  373. break;
  374. case _OPT_TILL:
  375. // 第一个无选项的参数识别为输入文件
  376. inImageFile = scriptArgv[UNOPTIND];
  377. break;
  378. case _OPT_TERR:
  379. _ftprintf(stderr, _T("[%d]: Extra parameters '%s'\n"), lineNumber, scriptArgv[OPTIND]);
  380. exit(1);
  381. break;
  382. default:
  383. _ftprintf(stderr, _T("[%d]: Unknown switch '-%c'\n"), lineNumber, K);
  384. exit(1);
  385. }
  386. }
  387. if(inImageFile == NULL)
  388. {
  389. _ftprintf(stderr, _T("[%d]: Needs input file\n"), lineNumber);
  390. exit(1);
  391. }
  392. // 调用image拼接手函数
  393. DrawImageFile(pGraphics, inImageFile, lineNumber, useTransparentColor, Color(tRGB[0],tRGB[1],tRGB[2],tRGB[3]), cut_rect[0], cut_rect[1], cut_rect[2], cut_rect[3], show_rect[0], show_rect[1], show_rect[2], show_rect[3], rote_matri[0], rote_matri[1], rote_matri[2]);
  394. return 0;
  395. }
  396. // 主函数入口
  397. int _tmain(int argc, TCHAR** argv)
  398. {
  399. if(argc<2)
  400. {
  401. // 无参数则退出
  402. _ftprintf(stdout, HELP_INFORMATION);
  403. return 0;
  404. }
  405. // 初始化传递参数
  406. int image_size[2] = {1280, 720};
  407. // 设置背景色ARGB
  408. byte bARGB[4] = {0};
  409. // IO文件
  410. TCHAR *inFile=NULL, *outFile=NULL, *jumpMark=NULL;
  411. // 开关解析
  412. int K = _OPT_TEOF;
  413. while((K=_tgetopt(argc, argv, (TCHAR*)_T("s:o:b:hS:O:B:H"))) != _OPT_TEOF)
  414. {
  415. switch(K)
  416. {
  417. case _T('s'):
  418. case _T('S'):
  419. if(OPTARG == NULL)
  420. {
  421. _ftprintf(stderr, _T("The switch '-s' needs a output image size like [[width],[height]]\n"));
  422. exit(1);
  423. }
  424. {
  425. TCHAR* pTcstr = _tcstok(OPTARG, _T(","));
  426. for(int i=0; i<2 && pTcstr; i++)
  427. {
  428. image_size[i] = _ttoi((TCHARFORMAT*)pTcstr);
  429. pTcstr = _tcstok(NULL, _T(","));
  430. }
  431. }
  432. break;
  433. case _T('o'):
  434. case _T('O'):
  435. if(OPTARG != NULL)
  436. {
  437. outFile = OPTARG;
  438. }
  439. break;
  440. case _T('j'):
  441. case _T('J'):
  442. if(OPTARG == NULL)
  443. {
  444. _ftprintf(stderr, _T("The switch '-j' needs a jump mark\n"));
  445. exit(1);
  446. }
  447. jumpMark = OPTARG;
  448. break;
  449. case _T('b'):
  450. case _T('B'):
  451. if(OPTARG == NULL)
  452. {
  453. _ftprintf(stderr, _T("The switch '-b' needs a background ARGB color like [[A],[R],[G],[B]]\n"));
  454. exit(1);
  455. }
  456. {
  457. TCHAR* pTcstr = _tcstok(OPTARG, _T(","));
  458. for(int i=0; i<4 && pTcstr; i++)
  459. {
  460. bARGB[i] = (byte)_ttoi((TCHARFORMAT*)pTcstr);
  461. pTcstr = _tcstok(NULL, _T(","));
  462. }
  463. }
  464. break;
  465. case _T('h'):
  466. case _T('H'):
  467. _ftprintf(stdout, HELP_INFORMATION);
  468. return 0;
  469. case _OPT_TILL:
  470. // 第一个无选项的参数识别为输入文件
  471. inFile = argv[UNOPTIND];
  472. break;
  473. case _OPT_TERR:
  474. _ftprintf(stderr, _T("Extra parameters '%s'\n"), argv[OPTIND]);
  475. exit(1);
  476. default:
  477. _ftprintf(stderr, _T("Unknown switch '-%c'\n"), K);
  478. exit(1);
  479. }
  480. }
  481. if(inFile == NULL)
  482. {
  483. _ftprintf(stderr, _T("Needs input file\n"));
  484. exit(1);
  485. }
  486. if(outFile == NULL)
  487. {
  488. _ftprintf(stderr, _T("Needs output file\n"));
  489. exit(1);
  490. }
  491. // 备份输出文件名
  492. TCHAR outFileS[MAX_PATH];
  493. _tcscpy(outFileS, outFile);
  494. // 识别扩展名
  495. TCHAR* outFileSuffix = _tcsrchr(outFile, _T('.'));
  496. int SN = IdentifyKey(outFileSuffix, (TCHAR**)IMAGE_SUFFIX);
  497. if(SN == -1)
  498. {
  499. _ftprintf(stderr, _T("Error output image suffix '%s'\n"), outFileSuffix);
  500. exit(1);
  501. }
  502. // 初始化GdiPlus
  503. ULONG_PTR gdipludToken;
  504. GdiplusStartupInput gdiplusInput;
  505. GdiplusStartup(&gdipludToken,&gdiplusInput,NULL);
  506. // 获取编码器ID
  507. CLSID clsid;
  508. if(! GetEncoderClsid((WCHAR*)IMAGE_TYPE[SN], &clsid))
  509. {
  510. _ftprintf(stderr, _T("Get the CLSID failed\n"));
  511. exit(1);
  512. }
  513. // 创建拼接位图
  514. Bitmap* pJoinImageMap = new Bitmap(image_size[0], image_size[1], PixelFormat32bppARGB);
  515. Graphics* pGraphics = new Graphics(pJoinImageMap);
  516. // 设置背景色ARGB
  517. Color bkColor(bARGB[0],bARGB[1],bARGB[2],bARGB[3]);
  518. pGraphics->Clear(bkColor);
  519. // 进入脚本解析阶段
  520. int scriptArgc, lineNumber = 0;
  521. TCHAR** scriptArgv = NULL;
  522. TCHAR scriptLine[MAX_BUFF_SIZE + 1];
  523. TCHAR scriptLineTmp[MAX_BUFF_SIZE + 1];
  524. TCHAR expandScriptLine[MAX_BUFF_SIZE + 1];
  525. FILE* fp = _tfopen(inFile, _T("rb"));
  526. if(fp == NULL)
  527. {
  528. _ftprintf(stderr, _T("Read input script: '%s' failed\n"), inFile);
  529. exit(1);
  530. }
  531. // 读取BOM头
  532. byte scriptFileBOM[2] = {0};
  533. fread(scriptFileBOM, 1, 2, fp);
  534. if(! (scriptFileBOM[0] == 0xFF && scriptFileBOM[1] == 0xFE) )
  535. {
  536. _ftprintf(stderr, _T("Error input script file: '%s', you must save it as a unicode encoding txt\n"), inFile);
  537. exit(1);
  538. }
  539. BOOL jumpScriptFlag = (jumpMark==NULL) ?TRUE :FALSE;
  540. // 执行脚本循环
  541. while(! feof(fp))
  542. {
  543. _fgetts(scriptLine, MAX_BUFF_SIZE, fp);
  544. // 计行
  545. lineNumber ++;
  546. // 去掉尾部换行符
  547. TCHAR *pLine = scriptLine, *pLineTmp = scriptLineTmp;
  548. while(*pLine == _T(' ') || *pLine == _T('\t'))
  549. {
  550. pLine ++;
  551. }
  552. while(*pLine != _T('\0') && *pLine != _T('\r') && *pLine != _T('\n'))
  553. {
  554. *(pLineTmp ++) = *(pLine ++);
  555. }
  556. *pLineTmp = _T('\0');
  557. // 启用环境变量扩展字串
  558. ExpandEnvironmentStrings(scriptLineTmp, expandScriptLine, MAX_BUFF_SIZE);
  559. // 解析脚本行标签
  560. if(*expandScriptLine == _T(':'))
  561. {
  562. if(jumpScriptFlag == FALSE)
  563. {
  564. int jumpMarkLen = _tcslen(jumpMark);
  565. TCHAR* expandMarkStr = expandScriptLine + 1;
  566. // 解析标签
  567. if(_tcsnicmp(expandMarkStr, jumpMark, jumpMarkLen) == 0)
  568. {
  569. if(
  570.     *(expandMarkStr + jumpMarkLen) == _T(' ')  ||
  571.     *(expandMarkStr + jumpMarkLen) == _T('\t') ||
  572.     *(expandMarkStr + jumpMarkLen) == _T('\0')
  573. )
  574. {
  575. jumpScriptFlag = TRUE;
  576. }
  577. }
  578. // 执行跳行
  579. continue;
  580. }
  581. else if(jumpMark != NULL)
  582. {
  583. // 退出脚本
  584. break;
  585. }
  586. }
  587. // 解析ECHO命令
  588. if(
  589.         (_tcsnicmp(expandScriptLine, _T("ECHO"), 4) == 0) &&
  590.         (
  591.             *(expandScriptLine+4) == _T(' ')  ||
  592.             *(expandScriptLine+4) == _T('\t')
  593.         )
  594. )
  595. {
  596. TCHAR* pExpandScriptLine = expandScriptLine + 4;
  597. while(*pExpandScriptLine == _T(' ') || *pExpandScriptLine == _T('\t'))
  598. {
  599. pExpandScriptLine ++;
  600. }
  601. // 拟化命令行参数
  602. scriptArgv = (TCHAR**)CommandLineToArgvW(pExpandScriptLine, &scriptArgc);
  603. // 调用脚本命令行解析函数
  604. ParseScript(scriptArgc, scriptArgv, lineNumber, pGraphics);
  605. // 释放局部空间
  606. LocalFree(scriptArgv);
  607. }
  608. // 解析EXIT命令
  609. else if(
  610.         (_tcsnicmp(expandScriptLine, _T("EXIT"), 4) == 0) &&
  611.         (
  612.             *(expandScriptLine+4) == _T(' ')  ||
  613.             *(expandScriptLine+4) == _T('\t') ||
  614.             *(expandScriptLine+4) == _T('\0')
  615.         )
  616. )
  617. {
  618. break;
  619. }
  620. }
  621. // 保存拼接图
  622. if(pJoinImageMap->Save((WCHAR*)outFileS, &clsid, NULL) != Gdiplus::Ok)
  623. {
  624. _ftprintf(stderr, _T("Save the image: '%s' failed\n"), outFileS);
  625. exit(1);
  626. }
  627. // 清理绘图工具
  628. DeleteObject(pGraphics);
  629. delete pJoinImageMap;
  630. // 关闭Gdiplus
  631. GdiplusShutdown(gdipludToken);
  632. return 0;
  633. }
复制代码

作者: 失控的疯子    时间: 2019-1-25 15:50

大佬啊============
作者: yy3yy3    时间: 2020-10-17 10:54

Jimg是一款控制台下拼图脚本工具,类似gawk的性质,但处理的是图片并非文本。可以将拼接好的图片出书为各种 ...
happy886rr 发表于 2017-9-9 21:48

似乎不错,不过帮助、范例太少了,不知道如何用。




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