01-31-2023, 03:44 AM 
	
	
	
		Hi all,
I'm setting up a script, and part of it is to scale the image to a max size of 256 for one type of texture and a max size of 128 for a different type of texture. That aspect isn't working, so I isolated it into a separate script, and it's still not working. I've managed to figured out where the issue is happening, but not why. Here's the isolated code:
The issue is the line where the scaleFactor is being determined. For whatever reason, scaleFactor = int(maxSize) / int(currentWidth) is giving a value of 0, even though maxSize is nonzero (defined as 256) and currentWidth is also nonzero (512 in the image I was testing). I used pdb.gimp_message() to verify the values right before the operation, and they're what I expect. Maybe I'm doing the division wrong? I also tried converting maxSize and currentWidth to integers (with int()), but that didn't change anything either. Any thoughts would be appreciated.
	
	
I'm setting up a script, and part of it is to scale the image to a max size of 256 for one type of texture and a max size of 128 for a different type of texture. That aspect isn't working, so I isolated it into a separate script, and it's still not working. I've managed to figured out where the issue is happening, but not why. Here's the isolated code:
Code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from gimpfu import*
    
def resizeMax(image, layer, texType):
    # Determine the max size based on the texture type:
    if texType == 0:
        # primary texture
        maxSize = 256
    else:
        # secondary texture
        maxSize = 128
    # Get the current dimensions of the image
    currentWidth = image.width
    currentHeight = image.height
    # Check which is bigger
    if currentWidth >= currentHeight:
        # Wide image or square
        scaleFactor = maxSize / currentWidth
        pdb.gimp_message("DEBUG: Scale Factor is")
        pdb.gimp_message(scaleFactor)
    else:
        # Tall image
        scaleFactor = maxSize / currentHeight
        pdb.gimp_message("DEBUG: Scale Factor is")
        pdb.gimp_message(scaleFactor)
    # Get the new sizes
    newWidth = scaleFactor * currentWidth
    newHeight = scaleFactor * currentHeight
    # scale the image accordingly
    pdb.gimp_image_scale(image, newWidth, newHeight)
    # Resize the layer to the image size
    pdb.gimp_layer_resize_to_image_size(layer)
    # Display the changes
    pdb.gimp_displays_flush()
def resizeMaxMain(image, layer):
    resizeMax(image, layer, 0)
    
register(
    "python_fu_test_resize_max",
    "",
    "",
    "BaconWizard17",
    "BaconWizard17",
    "January 2023",
    "Resize to Max Size",
    "*",
    [
        (PF_IMAGE, "image", "Input image", None),
        (PF_DRAWABLE, 'drawable', 'Layer, mask or channel', None)
    ],
    [],
    resizeMaxMain,
    menu='<Image>/Test'
)
main()The issue is the line where the scaleFactor is being determined. For whatever reason, scaleFactor = int(maxSize) / int(currentWidth) is giving a value of 0, even though maxSize is nonzero (defined as 256) and currentWidth is also nonzero (512 in the image I was testing). I used pdb.gimp_message() to verify the values right before the operation, and they're what I expect. Maybe I'm doing the division wrong? I also tried converting maxSize and currentWidth to integers (with int()), but that didn't change anything either. Any thoughts would be appreciated.
Modder/Skinner at MarvelMods.com using GIMP to create, edit, and export textures and previews more efficiently.
My GIMP scripts hosted on GitHub
	
My GIMP scripts hosted on GitHub

 

 
