TCAX 字幕特效制作工具官方论坛 | ASS | TCAS | Python | Aegisub | Lua

 找回密码
 新人加入
查看: 4624|回复: 0
打印 上一主题 下一主题

【图片转ASS工具】png2ass [复制链接]

Rank: 5Rank: 5

跳转到指定楼层
楼主
发表于 2018-12-2 15:25:29 |只看该作者 |倒序浏览
  1. # -*- coding: utf-8 -*-
  2. import sys
  3. from tcaxPy import *

  4. try:
  5.         input = sys.argv[1]
  6. except:
  7.         print('Error: none input image file!')
  8.         sys.exit()
  9. output = input
  10. width = 1280
  11. height = 720
  12. ass_header = """[Script Info]\r
  13. ; This script is generated by png2ass powered by TCAX 1.2.0\r
  14. ; Welcome to TCAX forum http://tcax.org\r
  15. ScriptType: v4.00+\r
  16. Collisions:Normal\r
  17. PlayResX:{width}\r
  18. PlayResY:{height}\r
  19. Timer:100.0000\r
  20. \r
  21. [V4+ Styles]\r
  22. Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding\r
  23. Style: TCMS,Arial,30,&H00FF0000,&HFFFF0000,&H000000FF,&HFF000000,0,0,0,0,100,100,0,0,0,1,0,5,15,15,10,1\r
  24. Style: TCPS,Arial,1,&HFFFFFFFF,&HFFFFFFFF,&HFFFFFFFF,&HFFFFFFFF,0,0,0,0,100,100,0,0,0,0,0,7,0,0,0,1\r
  25. \r
  26. [Events]\r
  27. Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text\r
  28. \r""".format(width=width, height=height)

  29. data = {
  30.         val_OutFile : output,
  31.         val_AssHeader : ass_header,
  32.         val_ResolutionX : width,
  33.         val_ResolutionY : height,
  34. }

  35. def png2ass():
  36.         file_name = GetVal(val_OutFile) + '.ass'
  37.         ass_header = GetVal(val_AssHeader)
  38.         ASS_FILE = CreateAssFile(file_name, ass_header)
  39.         ASS_BUF = []
  40.         PIX = ImagePix((input))
  41.         dx = (GetVal(val_ResolutionX) - PIX[1][0]) / 2 - PIX[0][0]        # x middle of the screen
  42.         dy = (GetVal(val_ResolutionY) - PIX[1][1]) / 2 - PIX[0][1]   # y middle of the screen

  43.         ## -- pix convert start
  44.         initPosX = dx + PIX[0][0]
  45.         initPosY = dy + PIX[0][1]
  46.         for h in range(PIX[1][1]):
  47.                 posY = initPosY + h
  48.                 for w in range(PIX[1][0]):
  49.                         posX = initPosX + w
  50.                         idx  = 4 * (h * PIX[1][0] + w)
  51.                         pixR = PIX[2][idx + 0]
  52.                         pixG = PIX[2][idx + 1]
  53.                         pixB = PIX[2][idx + 2]
  54.                         pixA = PIX[2][idx + 3]
  55.                         if pixA != 0:
  56.                                 ass_main(ASS_BUF, SubL(0, 1000, 0, Pix_Style), pos(posX, posY) + color1(FmtRGB(pixR, pixG, pixB)) + alpha1(255 - pixA), PixPt())
  57.         ## -- pix convert end
  58.         
  59.         WriteAssFile(ASS_FILE, ASS_BUF)         # write the buffer in memory to the file
  60.         FinAssFile(ASS_FILE)

  61. if __name__ == "__main__":
  62.         tcaxPy_InitData(data)
  63.         png2ass()
复制代码
PNG图片转ASS工具,基于TCAX库
参考自:http://www.tcax.org/forum.php?mod=viewthread&tid=176&extra=page%3D1

GitHub下载:https://github.com/emako/png2ass/releases
您需要登录后才可以回帖 登录 | 新人加入

GitHub|TCAX 主页

GMT+8, 2024-11-23 17:38

Powered by Discuz! X2

© 2001-2011 Comsenz Inc.

回顶部
RealH