コード例 #1
0
ファイル: gimp_spine.py プロジェクト: jclounge/gimp-spine
def spine_export(img, active_layer, compression, dir_name, json_filename, export_visible_only, reverse_draw_order, autocrop_layers, padding_amt):
    ''' Plugin entry point
    '''

    orig_img = img
    orig_active_layer = pdb.gimp_image_get_active_layer(orig_img)
    img = pdb.gimp_image_duplicate(orig_img)

    # Set up the initial JSON format
    output = {
        'bones': [{'name': 'root'}],
        'slots': [],
        'skins': {'default': {}},
        'animations': {}
    }
    slots = output['slots']
    attachments = output['skins']['default']

    # Iterate through the layers, extracting their info into the JSON output
    # and saving the layers as individual images
    for layer in img.layers:
       if (layer.visible or not(export_visible_only)):
               to_save = process_layer(img, layer, slots, attachments, reverse_draw_order, autocrop_layers, padding_amt)
               save_layers(img, to_save, compression, dir_name)

    # Write the JSON output
    if not json_filename:
        json_filename = os.path.splitext(os.path.basename(orig_img.filename))[0]

    with open(os.path.join(dir_name, '%s.json' % json_filename), 'w') as json_file:
        json.dump(output, json_file)

    pdb.gimp_image_delete(img)
    pdb.gimp_image_set_active_layer(orig_img, orig_active_layer)
コード例 #2
0
def add_layer(opacity=100, mode=0):
    image = gimp.image_list()[0]
    new_layer = gimp.Layer(image, "worms", image.width, image.height, 0,
                           opacity, mode)
    pdb.gimp_image_add_layer(image, new_layer, 0)
    pdb.gimp_image_set_active_layer(image, new_layer)
    drawable = pdb.gimp_image_active_drawable(image)
コード例 #3
0
ファイル: gimp_spine.py プロジェクト: jclounge/gimp-spine
def process_layer(img, layer, slots, attachments, reverse_draw_order, autocrop_layers, padding_amt):
    ''' Extracts the Spine info from each layer, recursing as necessary on
        layer groups. Returns all the layers it processed in a flat list.
    '''
    processed = []

    # If this layer is a layer has sublayers, recurse into them
    if hasattr(layer, 'layers'):
        for sublayer in layer.layers:
            processed.extend(process_layer(img, sublayer, slots, attachments, reverse_draw_order, autocrop_layers, padding_amt))
    else:
        pdb.gimp_image_set_active_layer(img, layer)

        if autocrop_layers:
            pdb.plug_in_autocrop_layer(img, layer)

        if padding_amt > 0:
            pdb.gimp_layer_resize(layer, layer.width + 2*padding_amt, layer.height + 2*padding_amt, padding_amt, padding_amt)

        layer_name = layer.name

        if reverse_draw_order:
            slots.append({
                'name': layer_name,
                'bone': 'root',
                'attachment': layer_name,
            })
        else:
            slots.insert(0, {
                'name': layer_name,
                'bone': 'root',
                'attachment': layer_name,
            })
        x, y = layer.offsets

        # Compensate for GIMP using the top left as the origin, vs Spine
        # using the center.
        x += math.floor(layer.width / 2)
        y += math.floor(layer.height / 2)

        # Center the image on Spine's x origin,
        x -= math.floor(img.width / 2)

        # Compensate for GIMP's y axis going from top to bottom, vs Spine
        # going bottom to top
        y = img.height - y

        attachments[layer_name] = {layer_name: {
            'x': x,
            'y': y,
            'rotation': 0,
            'width': layer.width,
            'height': layer.height,
        }}
        processed.append(layer)

    return processed