Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need help with small edit to a plug-in
#1
Question 
Hello! I do a lot of image work for my job and my little team really appreciates all the time and effort you all put into these plug-ins. Countless hours have been saved thanks to the work you all share and upload.
I was hoping I could find someone who could help write a small QOL edit a plug-in.

The plug-in is the Center Resize All Layers to Image Size created by Tin Tran over on http://gimplearn.net.

Would it be possible to have the code loop until it's Centered/Resized all layers and then delete the "Background" layer?


First I need to say: None of my team, myself included, is very good with GIMP. I'd still classify us all as novice, even after years. Some of them can barely understand what a "brush" or "layer" is and just follow a very basic step-by-step-with-pictures guide to get their basic edits done. I swear they're smart. Just... not with image work/programs.
We work with hundreds of images at a time. For the scaling/size, we typically open a new canvas with our desired size/dimensions, upload a ton of different sized images as layers, use that plug-in to center and resize all of the images to the canvas size, and then use another plug-in to export all layers as individual images. We export to a lot of different folders. Unfortunately, this means they also export the white Background layer to every folder as well. They will then go to every individual folder (sometimes a couple hundred) and delete the white background image.

It would be so much less of a headache to just have that layer deleted automatically before exporting.

Code:
#!/usr/bin/env python

# center_resize_all_layers_to_image_size.py
# Created by Tin Tran http://gimplearn.net
# License: GPLv3
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY# without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# To view a copy of the GNU General Public License
# visit: http://www.gnu.org/licenses/gpl.html
#
#
# ------------
#| Change Log |
# ------------
# Rel 1: Initial release.
#import string
#import Image
import random
from gimpfu import *
import math
#from array import array
#import sys
    
def python_tt_center_resize_all_layers_to_image_size(image, layer):
    #convert to index mode
    # pdb.gimp_image_convert_indexed(image,CONVERT_DITHER_NONE,CONVERT_PALETTE_GENERATE,colors,FALSE,TRUE,'ignored')
    # num_bytes,colormap = pdb.gimp_image_get_colormap(image);
    # num_bytes_per_color = len(colormap)/colors
    # pdb.gimp_image_convert_rgb(image) #convert it back to RGB
    non_empty,x1,y1,x2,y2 = pdb.gimp_selection_bounds(image)
    if (non_empty == TRUE):
        width = x2-x1
        height = y2-y1
        for l in image.layers:
            pdb.gimp_layer_scale(l,width,height,TRUE)
            pdb.gimp_layer_set_offsets(l,x1,y1)
    else:    
        for l in image.layers:
            pdb.gimp_layer_scale(l,image.width,image.height,TRUE)
            pdb.gimp_layer_set_offsets(l,0,0)

register(
    "python_fu_tt_center_resize_all_layers_to_image_size",                          
    "Center Resize All Layers To Image Size",
    "Center Resize All Layers To Image Size",
    "Tin Tran",
    "Tin Tran",
    "August 2020",
    "<Image>/Python-Fu/Center Resize All Layers To Image Size",             #Menu path
    "RGB*, GRAY*",
    [
    # (PF_SPINNER, "width", "Width:", 2000, (10, 3000, 10)),
    # (PF_SPINNER, "height", "Height:", 2500, (10, 3000, 10)),
    ],
    [],
    python_tt_center_resize_all_layers_to_image_size)

main()
Reply


Messages In This Thread
Need help with small edit to a plug-in - by Fizzgig - 03-22-2022, 09:18 PM

Forum Jump: