Application in Go
See the entire codebase here on GitHubPurpose and overview
I wanted to use my plug-in without opening up Gimp myself, selecting the plug-in from the menu and setting all the parameters manually, so I created this application to automate this. That way, I have a fully automated process which would handle everything for me. The application opens up Gimp automatically in the background and runs my plug-in for the given image. Parameters such as background color, padding and export path are all handled by the app, and I got it hardcoded as I have one style for my images at the moment. This could be improved on in the future if there is a need for dynamically changing them when using the application. Here is a quick overview of the application:
- An image can be dropped onto the app icon or selected using a file dialog. Only jpg files are supported.
- Creates an output folder on the desktop if it doesn't already exist.
- Sets a new image name and ensures there isn't already an image with the same name in the output folder. If there is, the name is appended with number.
- Runs a command to open GIMP in the background and use the plug-in.
- Saves the new image in the output directory.
- Uses toast notifications to inform the user of ongoing actions.
Key parts of the application
func getImagePath() (string, error) {
argumentsPassed := len(os.Args)
if argumentsPassed > 2 {
return "", errors.New("Dropping multiple files is not supported")
}
if argumentsPassed > 1 {
// File drop
return os.Args[1], nil
}
// File dialog
imagePath, err := dialog.File().Filter("Images", "jpg", "jpeg").Load()
if err != nil {
return "", err
}
return imagePath, nil
}
func setFileExportPath(overlayImagePath string) (string, error) {
homeDir, err := os.UserHomeDir()
if err != nil {
return "", err
}
outputFolder := filepath.Join(homeDir, "Desktop", "InstaPictures")
if _, err := os.Stat(outputFolder); os.IsNotExist(err) {
err = os.MkdirAll(outputFolder, 0755)
if err != nil {
return "", err
}
}
overlayImageExt := filepath.Ext(overlayImagePath)
baseName := strings.TrimSuffix(filepath.Base(overlayImagePath), overlayImageExt)
outputImageName := baseName + "-output" + overlayImageExt
exportPath := filepath.Join(outputFolder, outputImageName)
return ifPathExistsReturnNewValidOne(exportPath), nil
}
func runGimpPlugin(padding, r, g, b int, imageOverlayPath, exportPath string) {
batchCmd := fmt.Sprintf(`pdb.python_fu_create_new_insta_image(%d, %d, %d, %d, "%s", "%s")`,
padding, r, g, b,
strings.ReplaceAll(imageOverlayPath, `\`, `/`),
strings.ReplaceAll(exportPath, `\`, `/`))
cmd := exec.Command("gimp-2.10", "--batch-interpreter=python-fu-eval", "-i", "-b", batchCmd)
// Hide GIMP console window on Windows
cmd.SysProcAttr = &syscall.SysProcAttr{
HideWindow: true,
}
cmd.Run()
}
Application demo

