Ejemplo n.º 1
0
def main(input_folder=".", output_folder="../thumb"):
    CleanDirectory(output_folder, "", "*.*")
    for image_file in glob.glob(os.path.join(input_folder, '*.png')):
        image_filename = os.path.basename(image_file)
        # print("Current file: {}").format(image_file)

        print("Resizing Image: {}").format(image_filename)
        image = PIL_Helper.LoadImage(image_file)
        image_thumb = PIL_Helper.ResizeImage(image, VASSAL_SCALE)
        SaveCard(os.path.join(output_folder, image_filename), image_thumb)
Ejemplo n.º 2
0
def AddCardArt(image, filename, anchor):
    if filename == "NOART":
        return
    if os.path.exists(os.path.join(CardPath, filename)):
        art = PIL_Helper.LoadImage(os.path.join(CardPath, filename))
    else:
        art = random.choice(ArtMissing)
    # Find desired height of image based on width of 600 px
    w, h = art.size
    h = int((float(ART_WIDTH) / w) * h)
    # Resize image to fit in frame
    art = PIL_Helper.ResizeImage(art, (ART_WIDTH, h))
    image.paste(art, anchor)
Ejemplo n.º 3
0
def SaveCard(filepath, image, scale=1, convert_to_cmyk=False):
    '''
    If the filepath already exists, insert _001 just before the
    extension. If that exists, increment the number until we get to
    a filepath that doesn't exist yet.
    '''
    if os.path.exists(filepath):
        basepath, extension = os.path.splitext(filepath)
        i = 0
        while os.path.exists(filepath):
            i += 1
            filepath = "{}_{:>03}{}".format(basepath, i, extension)
    w, h = image.size
    new_w = int(scale * w)
    new_h = int(scale * h)
    image = PIL_Helper.ResizeImage(image, (new_w, new_h))
    if convert_to_cmyk:
        PIL_Helper.ConvertToCmyk(image)
    image.save(filepath, dpi=(300, 300))
Ejemplo n.º 4
0
def BuildCard(data):
    picture = None
    title = None

    if type(data).__name__ == 'dict':
        card = data
        card_type = data['type']
        picture = data.get('picture', None)
        title = data.get('title', None)
    else:
        card = data.strip('\n').strip('\r').replace(r'\n', '\n').split('`')
        card_type = card[TYPE]
        if len(card) >= 2:
            picture = card[PICTURE]
        if len(card) > 2:
            title = card[TITLE]

    try:
        im = PickCardFunc(card_type, card)
        im = AddWatermark(im)
        if picture is not None:
            if title is not None:
                filename = FixFileName(card_type + "_" + title)
            else:
                filename = FixFileName(card_type + "_" + picture)
            SaveCard(os.path.join(BleedsPath, filename), im)
            im_crop = im.crop(croprect)
            SaveCard(os.path.join(CropPath, filename), im_crop)
            im_vassal = PIL_Helper.ResizeImage(im_crop, VASSAL_SCALE)
            SaveCard(os.path.join(VassalPath, filename), im_vassal)
        else:
            im_crop = im.crop(croprect)

    except Exception as e:
        print "Warning, Bad Card: {0}".format(data)
        traceback.print_exc()
        im_crop = MakeBlankCard().crop(croprect)
    return im_crop
Ejemplo n.º 5
0
def BuildCard(linein):
    tags = linein.strip('\n').strip('\r').replace(r'\n', '\n').split('`')
    try:
        im = PickCardFunc(tags[TYPE], tags)
        if len(tags) >= 2:
            if len(tags) == 2:
                filename = FixFileName(tags[0] + "_" + tags[1])
            else:
                filename = FixFileName(tags[0] + "_" + tags[3])
            SaveCard(os.path.join(BleedsPath, filename), im)
            im_crop = im.crop(croprect)
            SaveCard(os.path.join(CropPath, filename), im_crop)
            im_vassal = PIL_Helper.ResizeImage(im_crop, VASSAL_SCALE)
            SaveCard(os.path.join(VassalPath, filename), im_vassal)
        else:
            im_crop = im.crop(croprect)
        #MakeVassalCard(im_cropped)
    except Exception as e:
        print "Warning, Bad Card: {0}".format(tags)
        traceback.print_exc()
        im_crop = MakeBlankCard().crop(croprect)
    #im.show()  # TEST
    return im_crop