def pythonSaveToPSD(image):

    # Prep
    pdb.gimp_image_undo_group_start(image)
    pdb.gimp_context_push()

    # Code
    drawable = pdb.gimp_image_get_active_drawable(image)
    filename = pdb.gimp_image_get_filename(image)
    temp = filename.replace("_CLEAN", "")
    temp2 = temp.replace("_EDIT", "")
    temp = temp2.replace("_XCF", "")
    filename = temp.replace("_PSD", "")
    path = os.path.dirname(filename)
    path += "_PSD"
    name = os.path.basename(filename)
    out_psd = os.path.join(path, name)
    out_psd = os.path.splitext(out_psd)[0] + '.psd'

    # Create folder
    if not os.path.exists(path):
        os.makedirs(path)

    # Save in PSD
    pdb.gimp_file_save(image, drawable, out_psd, out_psd)
    pdb.gimp_image_clean_all(image)

    # Finish
    pdb.gimp_context_pop()
    pdb.gimp_image_undo_group_end(image)
    pdb.gimp_displays_flush()
예제 #2
0
def pythonSaveToClean(image):

    # Prep
    pdb.gimp_image_undo_group_start(image)
    pdb.gimp_context_push()

    # Code
    filename_old = pdb.gimp_image_get_filename(image)
    filename = filename_old.replace("_CLEAN", "")
    # drawable = pdb.gimp_image_get_active_drawable(image)
    path = os.path.dirname(filename)
    path += "_CLEAN"
    name = os.path.basename(filename)
    out_file = os.path.join(path, name)

    # Create CLEAN folder
    if not os.path.exists(path):
        os.makedirs(path)

    # Merge visible layers in new image and export in CLEAN folder
    new_image = pdb.gimp_image_duplicate(image)
    layer = pdb.gimp_image_merge_visible_layers(new_image, CLIP_TO_IMAGE)
    pdb.gimp_file_save(new_image, layer, out_file, out_file)
    pdb.gimp_image_delete(new_image)
    pdb.gimp_image_clean_all(image)

    # Finish
    pdb.gimp_context_pop()
    pdb.gimp_image_undo_group_end(image)
    pdb.gimp_displays_flush()
def pythonSaveToEditJpeg(image):

    # Prep
    pdb.gimp_image_undo_group_start(image)
    pdb.gimp_context_push()

    # Code
    # drawable = pdb.gimp_image_get_active_drawable(image)
    filename = pdb.gimp_image_get_filename(image)
    temp = filename.replace("_CLEAN", "")
    temp2 = temp.replace("_EDIT", "")
    filename = temp2.replace("_XCF", "")
    path = os.path.dirname(filename)
    path += "_EDIT"
    name = os.path.basename(filename)
    out_file = os.path.join(path, name)
    out_file = os.path.splitext(out_file)[0] + '.jpg'

    # Create _EDIT folder
    if not os.path.exists(path):
        os.makedirs(path)

    # Merge visible layers in new image and export in JPEG
    new_image = pdb.gimp_image_duplicate(image)
    layer = pdb.gimp_image_merge_visible_layers(new_image, CLIP_TO_IMAGE)
    pdb.gimp_file_save(new_image, layer, out_file, out_file)
    pdb.gimp_image_delete(new_image)
    pdb.gimp_image_clean_all(image)

    # Finish
    pdb.gimp_context_pop()
    pdb.gimp_image_undo_group_end(image)
    pdb.gimp_displays_flush()
예제 #4
0
def create_base_alphabet(font, font_size, directory_base):
    suffix = '.xbm'
    for c_gen, c_prefix in (
        (map(chr, xrange(ord('A'),
                         ord('Z') + 1)), 'upper'),
        (map(chr, xrange(ord('a'),
                         ord('z') + 1)), 'lower'),
        (map(chr, xrange(ord('0'),
                         ord('9') + 1)), 'number'),
    ):
        for c in c_gen:
            prefix = '%s%c' % (c_prefix, c)
            filename = '%s%s' % (prefix, suffix)

            image = gimp.Image(1, 1, INDEXED)
            image.disable_undo()

            # necessary ?
            pdb.gimp_context_push()

            gimp.set_foreground((0.0, 0.0, 0.0))

            x = y = border = 0
            layer = pdb.gimp_text_fontname(image, None, x, y, c, border, True,
                                           font_size, PIXELS, font)

            image.resize(layer.width, layer.height, 0, 0)

            filepath = join(directory_base, filename)
            pdb.gimp_file_save(image, layer, filepath, '?')
            #pdb.file_xbm_save(RUN_NONINTERACTIVE, image, None, filename, filepath, '', 0, 0, 0)
            # find out how to properly call file_xbm_save so we can avoid this crap
            with open(filepath, 'r+b') as file_h:
                lines = file_h.readlines()
                file_h.seek(0)
                for line in lines:
                    if '_' in line:
                        if '_hot' not in line:
                            file_h.write(line.replace('_', prefix + '_'))
                    else:
                        file_h.write(line)
                file_h.truncate()

            pdb.gimp_image_delete(image)

            # necessary ?
            pdb.gimp_context_pop()
예제 #5
0
def create_base_alphabet(font, font_size, directory_base):
    suffix = '.xbm'
    for c in string.printable:
        # Only need the first guard to prevent \x0b and \x0c, but meh
        if not ' ' <= c <= '\x7f':
            continue
        prefix = 'ascii0x%02x' % ord(c)
        filename = '%s%s' % (prefix, suffix)

        image = gimp.Image(1, 1, INDEXED)
        image.disable_undo()

        # necessary ?
        pdb.gimp_context_push()

        gimp.set_foreground((0.0, 0.0, 0.0))

        x = y = border = 0
        layer = pdb.gimp_text_fontname(image, None, x, y, c, border, True,
                                       font_size, PIXELS, font)

        if layer is None:
            print 'Failed to handle %r' % c

        else:
            image.resize(layer.width, layer.height, 0, 0)

            filepath = join(directory_base, filename)
            pdb.gimp_file_save(image, layer, filepath, '?')
            #pdb.file_xbm_save(RUN_NONINTERACTIVE, image, None, filename, filepath, '', 0, 0, 0)
            # find out how to properly call file_xbm_save so we can avoid this section
            with open(filepath, 'r+b') as file_h:
                lines = file_h.readlines()
                file_h.seek(0)
                for line in lines:
                    if '_' in line:
                        if '_hot' not in line:
                            file_h.write(line.replace('_', prefix + '_'))
                    else:
                        file_h.write(line)
                file_h.truncate()

        pdb.gimp_image_delete(image)

        # necessary ?
        pdb.gimp_context_pop()
def create_base_alphabet(font, font_size, directory_base):
    suffix = '.xbm'
    for c in string.printable:
        # Only need the first guard to prevent \x0b and \x0c, but meh
        if not ' ' <= c <= '\x7f':
            continue
        prefix = 'ascii0x%02x' % ord(c)
        filename = '%s%s' % (prefix, suffix)

        image = gimp.Image(1, 1, INDEXED)
        image.disable_undo()

        # necessary ?
        pdb.gimp_context_push()

        gimp.set_foreground( (0.0, 0.0, 0.0) )

        x = y = border = 0
        layer = pdb.gimp_text_fontname(image, None, x, y, c, border, True, font_size, PIXELS, font)

        if layer is None:
            print 'Failed to handle %r' % c

        else:
            image.resize(layer.width, layer.height, 0, 0)

            filepath = join(directory_base, filename)
            pdb.gimp_file_save(image, layer, filepath, '?')
            #pdb.file_xbm_save(RUN_NONINTERACTIVE, image, None, filename, filepath, '', 0, 0, 0)
            # find out how to properly call file_xbm_save so we can avoid this section
            with open(filepath, 'r+b') as file_h:
                lines = file_h.readlines()
                file_h.seek(0)
                for line in lines:
                    if '_' in line:
                        if '_hot' not in line:
                            file_h.write(line.replace('_', prefix+'_'))
                    else:
                        file_h.write(line)
                file_h.truncate()

        pdb.gimp_image_delete(image)

        # necessary ?
        pdb.gimp_context_pop()
def create_base_alphabet(font, font_size, directory_base):
    suffix = '.xbm'
    for c_gen, c_prefix in ( (map(chr, xrange(ord('A'), ord('Z')+1)), 'upper'),
                             (map(chr, xrange(ord('a'), ord('z')+1)), 'lower'),
                             (map(chr, xrange(ord('0'), ord('9')+1)), 'number'), ):
        for c in c_gen:
            prefix = '%s%c' % (c_prefix, c)
            filename = '%s%s' % (prefix, suffix)

            image = gimp.Image(1, 1, INDEXED)
            image.disable_undo()

            # necessary ?
            pdb.gimp_context_push()

            gimp.set_foreground( (0.0, 0.0, 0.0) )

            x = y = border = 0
            layer = pdb.gimp_text_fontname(image, None, x, y, c, border, True, font_size, PIXELS, font)

            image.resize(layer.width, layer.height, 0, 0)

            filepath = join(directory_base, filename)
            pdb.gimp_file_save(image, layer, filepath, '?')
            #pdb.file_xbm_save(RUN_NONINTERACTIVE, image, None, filename, filepath, '', 0, 0, 0)
            # find out how to properly call file_xbm_save so we can avoid this crap
            with open(filepath, 'r+b') as file_h:
                lines = file_h.readlines()
                file_h.seek(0)
                for line in lines:
                    if '_' in line:
                        if '_hot' not in line:
                            file_h.write(line.replace('_', prefix+'_'))
                    else:
                        file_h.write(line)
                file_h.truncate()

            pdb.gimp_image_delete(image)

            # necessary ?
            pdb.gimp_context_pop()
예제 #8
0
def stickerify_bordure(image, current_layer, black_grow=3, white_grow=12, shadow=True, canvas_increase=0, resize=False):
    def duplicate_layer():
        copy = current_layer.copy()
        image.add_layer(copy)
        # copy is added above so we want to go down a bit
        image.active_layer = current_layer
        return copy

    def fill_black():
        pdb.gimp_edit_bucket_fill(current_layer, 1, 0, 100, 255, 0, 0, 0)

    def fill_white():
        pdb.gimp_edit_bucket_fill(current_layer, 0, 0, 100, 255, 0, 0, 0)

    def set_colors():
        pdb.gimp_context_set_foreground((255, 255, 255))
        pdb.gimp_context_set_background((0, 0, 0))

    pdb.gimp_context_push()
    pdb.gimp_image_undo_group_start(image)

    # clean selection to avoid bugs
    pdb.gimp_selection_none(image)

    set_colors()

    # resize early to avoid compressing the bordure
    if resize:
        width, height = image.width, image.height

        if width == height:
            new_width, new_height = 512, 512
        elif width > height:
            new_width, new_height = 512, int(height * (512.0 / width))
        elif width < height:
            new_width, new_height = int(width * (512.0 / height)), 512

        pdb.gimp_image_scale(image, new_width, new_height)

    if canvas_increase:
        width, height = image.width, image.height

        width_increase = int(width * (canvas_increase / 100))
        height_increase = int(height * (canvas_increase / 100))

        pdb.gimp_image_resize(image,
                              width + width_increase,
                              height + height_increase,
                              int(width_increase / 2),
                              int(height_increase / 2))

        pdb.gimp_layer_resize_to_image_size(current_layer)

    duplicate_layer()

    # alpha to selection
    pdb.gimp_image_select_item(image, 0, current_layer)

    pdb.gimp_selection_grow(image, black_grow)
    fill_black()

    second_layer = duplicate_layer()

    pdb.gimp_selection_grow(image, white_grow)
    fill_white()

    if shadow:
        duplicate_layer()

        fill_black()

        current_layer.translate(8, 8)

        pdb.gimp_selection_all(image)
        pdb.plug_in_gauss(image, current_layer, 20, 20, 0)
        pdb.gimp_layer_set_opacity(current_layer, 70)

    pdb.gimp_image_merge_down(image, second_layer, 0)

    if shadow:
        pdb.gimp_image_merge_down(image, image.active_layer, 0)

    pdb.gimp_layer_set_name(image.active_layer, "Sticker bordure")

    pdb.gimp_selection_none(image)

    pdb.gimp_image_undo_group_end(image)
    pdb.gimp_context_pop()

    pdb.gimp_displays_flush()
예제 #9
0
def stickerify_bordure(image,
                       tdrawable,
                       black_grow=3,
                       white_grow=12,
                       shadow=True):
    def duplicate_layer():
        copy = current_layer.copy()
        image.add_layer(copy)
        # copy is added above so we want to go down a bit
        image.active_layer = current_layer
        return copy

    def fill_black():
        pdb.gimp_edit_bucket_fill(current_layer, 1, 0, 100, 255, 0, 0, 0)

    def fill_white():
        pdb.gimp_edit_bucket_fill(current_layer, 0, 0, 100, 255, 0, 0, 0)

    def set_colors():
        pass

    pdb.gimp_context_push()
    pdb.gimp_image_undo_group_start(image)

    pdb.gimp_context_set_foreground((255, 255, 255))
    pdb.gimp_context_set_background((0, 0, 0))

    set_colors()

    current_layer = image.active_layer

    duplicate_layer()

    # alpha to selection
    pdb.gimp_image_select_item(image, 0, current_layer)

    pdb.gimp_selection_grow(image, black_grow)
    fill_black()

    second_layer = duplicate_layer()

    pdb.gimp_selection_grow(image, white_grow)
    fill_white()

    if shadow:
        duplicate_layer()

        fill_black()

        current_layer.translate(8, 8)

        pdb.gimp_selection_all(image)
        pdb.plug_in_gauss(image, current_layer, 20, 20, 0)
        pdb.gimp_layer_set_opacity(current_layer, 70)

    pdb.gimp_image_merge_down(image, second_layer, 0)

    if shadow:
        pdb.gimp_image_merge_down(image, image.active_layer, 0)

    pdb.gimp_image_undo_group_end(image)
    pdb.gimp_context_pop()

    pdb.gimp_displays_flush()