TCAX 字幕特效制作工具官方论坛 | ASS | TCAS | Python | Aegisub | Lua
标题:
【图片转ASS工具】png2ass
[打印本页]
作者:
mccoy39082
时间:
2018-12-2 15:25:29
标题:
【图片转ASS工具】png2ass
# -*- coding: utf-8 -*-
import sys
from tcaxPy import *
try:
input = sys.argv[1]
except:
print('Error: none input image file!')
sys.exit()
output = input
width = 1280
height = 720
ass_header = """[Script Info]\r
; This script is generated by png2ass powered by TCAX 1.2.0\r
; Welcome to TCAX forum http://tcax.org\r
ScriptType: v4.00+\r
Collisions:Normal\r
PlayResX:{width}\r
PlayResY:{height}\r
Timer:100.0000\r
\r
[V4+ Styles]\r
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
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
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
\r
[Events]\r
Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text\r
\r""".format(width=width, height=height)
data = {
val_OutFile : output,
val_AssHeader : ass_header,
val_ResolutionX : width,
val_ResolutionY : height,
}
def png2ass():
file_name = GetVal(val_OutFile) + '.ass'
ass_header = GetVal(val_AssHeader)
ASS_FILE = CreateAssFile(file_name, ass_header)
ASS_BUF = []
PIX = ImagePix((input))
dx = (GetVal(val_ResolutionX) - PIX[1][0]) / 2 - PIX[0][0] # x middle of the screen
dy = (GetVal(val_ResolutionY) - PIX[1][1]) / 2 - PIX[0][1] # y middle of the screen
## -- pix convert start
initPosX = dx + PIX[0][0]
initPosY = dy + PIX[0][1]
for h in range(PIX[1][1]):
posY = initPosY + h
for w in range(PIX[1][0]):
posX = initPosX + w
idx = 4 * (h * PIX[1][0] + w)
pixR = PIX[2][idx + 0]
pixG = PIX[2][idx + 1]
pixB = PIX[2][idx + 2]
pixA = PIX[2][idx + 3]
if pixA != 0:
ass_main(ASS_BUF, SubL(0, 1000, 0, Pix_Style), pos(posX, posY) + color1(FmtRGB(pixR, pixG, pixB)) + alpha1(255 - pixA), PixPt())
## -- pix convert end
WriteAssFile(ASS_FILE, ASS_BUF) # write the buffer in memory to the file
FinAssFile(ASS_FILE)
if __name__ == "__main__":
tcaxPy_InitData(data)
png2ass()
复制代码
PNG图片转ASS工具,基于TCAX库
参考自:
http://www.tcax.org/forum.php?mod=viewthread&tid=176&extra=page%3D1
GitHub下载:
https://github.com/emako/png2ass/releases
欢迎光临 TCAX 字幕特效制作工具官方论坛 | ASS | TCAS | Python | Aegisub | Lua (http://tcax.org/)
Powered by Discuz! X2