0

This plug-in works fine when I run it by itself, but when I add it as a procedure to Batch Image Manipulation Plugin (BIMP), it only outputs the image as 412x316 without the borders that I want at 640x360.

from gimpfu import *

def resize_canvas(image, drawable):
    # Resize the image
    pdb.gimp_image_scale(image, 412, 316)

    # Get the new width and height of the image
    width, height = pdb.gimp_image_width(image), pdb.gimp_image_height(image)
    
    # Change the canvas size
    pdb.gimp_image_resize(image, 640, 360, 0, 0)

    # Calculate the x and y coordinates to center the image
    x = (640 - width) / 2
    y = (360 - height) / 2

    # Center the image on the canvas
    pdb.gimp_layer_set_offsets(drawable, x, y)

register(
    "python_fu_resize_canvas",
    "Resize and center an image",
    "Resize an image and center it on a canvas",
    "Name",
    "Name",
    "2023",
    "Resize and Center",
    "",
    [
        (PF_IMAGE, "image", "Input image", None),
        (PF_DRAWABLE, "drawable", "Input drawable", None)
    ],
    [],
    resize_canvas,
    menu="<Image>/Filters/Misc"
)

main()

I'm trying to make it so there's a transparent border around the 412x316 image that makes the image 640x360.

Progman
  • 16,827
  • 6
  • 33
  • 48
  • I don't know the answer to this, but since you have the code you can put it in a script that loops over the files. See [this](https://stackoverflow.com/questions/44430081/how-to-run-python-scripts-using-gimpfu-from-windows-command-line/44435560#44435560) for an example... – xenoid Jan 29 '23 at 12:52
  • Also, this is very easy to do with ImageMagick: `convert -page 640x360+114+22 412x316.png -background none -layers flatten 640x360.png` – xenoid Jan 29 '23 at 13:09

0 Answers0