Esempio n. 1
0
def apply_template(template_path, text):
    pct_file = pct_titles.PctFile()
    pct_data = io.BytesIO()
    with io.open(template_path, 'rb') as f:
        pct_file.read(f)

        for item in pct_file.elements:
            if isinstance(item, pct_titles.TitleText):
                item.text = item.text.replace(b"#MARKER", text.encode('utf-8'))

        pct_file.aaf_mode = True
        pct_file.write(pct_data)

    return bytearray(pct_data.getvalue())
Esempio n. 2
0
def read_pct_data(pct_path):
    pct_file = pct_titles.PctFile()
    try:
        pct_file.read(pct_path)
    except:
        print "error reading %s" % pct_path
        print traceback.format_exc()
        return None

    data = StringIO()

    pct_file.aaf_mode = True
    pct_file.write(data)

    return bytearray(data.getvalue())
Esempio n. 3
0
def generate_test_title():
    pct = pct_titles.PctFile()

    text = pct_titles.TitleText("text in roughly in the center")

    width = 865
    height = 485

    # min_y, min_x , max_y, max_x
    text.bbox = (107, 217, 379, 647)
    text.fill_color = [65535, 0, 0]  # red
    text.justify = 0x0001

    text_format = pct_titles.TextFormat()
    text_format.font_size = 48 * 2
    text.text_formating.append(text_format)

    rect = pct_titles.TitleRectangle()
    rect.fill_color = [0, 65535, 0]

    edge = 10
    rect.bbox = [edge, edge, height - edge, width - edge]

    oval = pct_titles.TitleOval()
    oval.fill_color = [0, 0, 65535]

    line = pct_titles.TitleLine()
    line.line_width = 10

    line2 = pct_titles.TitleLine()
    line2.line_width = 10
    line2.bbox = [height, 0, 0, width]

    pct.add_element(rect)
    pct.add_element(oval)
    pct.add_element(line)
    pct.add_element(line2)
    pct.add_element(text)

    return pct
Esempio n. 4
0
def render_pct(src, dst):
    pct = pct_titles.PctFile()
    pct.read(src)
    size = "865x485"  # this seems to be the base resolution

    img = cythonmagick.Image(size=size, color="grey")
    #convert -list font

    for i, item in enumerate(pct.elements):
        render_item(pct, img, item, os.path.dirname(dst))

    img.resize("720x486!")

    name, ext = os.path.splitext(dst)
    if ext and ext.lower() in (
            ".pict",
            '.pct',
    ):
        img.magick = 'pict'
        data = StringIO(img.tostring())
        f = open(dst, 'wb')
        pct.embed(data, f)
    else:
        img.write(dst)
Esempio n. 5
0
import pct_titles
import sys
pct = pct_titles.PctFile()

pct.read(sys.argv[1])


pct.write("rewrite.pct")