#!/usr/bin/env python
# -*- coding: utf-8 -*-

from gimpfu import *

gettext.install("gimp20-python", gimp.locale_directory, unicode=True)

def resize_test(image, drawable, option):
    new_width = (image.width - (image.width * 50 / 100))
    new_height = (image.height - (image.height * 50 / 100))
    
    image.undo_group_start()
    
    # pdb.gimp_image_resize
    if option == 0:
        pdb.gimp_image_resize(image, new_width, new_height, 0, 0)
        
    # drawable_transform_scale > image_resize_to_layer
    if option == 1:
        pdb.gimp_drawable_transform_scale_default(drawable, 0, 0, new_width, new_height, False, 0)
        pdb.gimp_image_resize_to_layers(image)

    # pdb.gimp_layer_scale > pdb.plug_in_autocrop
    if option == 2:
        pdb.gimp_layer_scale(drawable, new_width, new_height, False)
        pdb.plug_in_autocrop(image, drawable)
    
    # pdb.gimp_image_scale
    if option == 3:
        pdb.gimp_image_scale(image, new_width, new_height)
        
    image.undo_group_end()
    
register(
    "resize-test",
    N_("Resize Test"),
    "Resize Test",
    "Jerry Baker",
    "Jerry Baker",
    "03/12/2009",
    N_("Resize Test"),
    "RGB*, GRAY*, INDEXED*",
    [
        # --- Parameters
        (PF_IMAGE, "image", _("Image"), None),
        (PF_DRAWABLE, "drawable", _("Drawable"), None),
        (PF_OPTION, "option", _("Select Test:"), 0, (_("pdb.gimp_image_resize"),
                                                     _("drawable_transform_scale > image_resize_to_layer"),
                                                     _("pdb.gimp_layer_scale > pdb.plug_in_autocrop"),
                                                     _("pdb.gimp_image_scale"))),
    ],
    [],
    resize_test,
    menu="<Image>/Test",
    domain=("gimp20-python", gimp.locale_directory)
    )

main()
