Assuming this is what you need, this will create a user dialog and you can find the image using a directory option. The image is place in the center of the canvas
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from gimpfu import *
def open_an_image(filename):
img = pdb.gimp_image_new(1920, 1080, RGB)
imagLayer = pdb.gimp_file_load_layer(img, filename)
pdb.gimp_image_add_layer(img, imagLayer, 0)
#Center the image to the canvas
imagLayer.set_offsets((img.width - imagLayer.width) / 2, (img.height - imagLayer.height) / 2)
pdb.gimp_display_new(img)
register(
"open_an_image",
"Open any image", #Short description
"Open any type of image", #Long description
"Your name",
"Your name",
"2021",
"Open my favorite image", #This is how you want it to appear in GIMP menu
"",
[
(PF_FILENAME, "filename", "Image:", None), #Directory option
],
[],
open_an_image, menu="<Image>/Python-Fu/Open my favorite image"), #This is how you want it to appear in GIMP menu
main()
Or you can center the image and make the image as high of the canvas
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#Above codings
#1. Python Source Code Encodings
#2. Most popular Python Source Code Encodings (Use both)
from gimpfu import * #This willgives you all of the constants, the procedural database (pdb), and gimp (Everything that belong to GIMP)
def open_an_image(filename): #Name of main function and variables
img = pdb.gimp_image_new(1920, 1080, RGB) #This function opens a new image with the size given and the image mode colors
imagLayer = pdb.gimp_file_load_layer(img, filename) #This will open or load image from directory
pdb.gimp_image_add_layer(img, imagLayer, 0) #Add or insert the layer for the image that it will open
#Center the image and make it big
factor = min (float(img.width) / imagLayer.width, float(img.height) / imagLayer.height)
imagLayer.scale(int(imagLayer.width * factor), int(imagLayer.height * factor))
imagLayer.set_offsets((img.width - imagLayer.width) / 2, (img.height - imagLayer.height) / 2)
pdb.gimp_display_new(img)
register(
"open_an_image",
"Open any image", #Short description
"Open any type of image", #Long description
"Your name",
"Your name",
"2021",
"Open my favorite image", #This is how you want it to appear in GIMP menu
"",
[
(PF_FILENAME, "filename", "Image:", None), #Directory option
],
[],
open_an_image, menu="<Image>/Python-Fu/Open my favorite image"), #This is how you want it to appear in GIMP menu
main()