0

My goal is scaling an image using python-fu library for gimp in a uniform way. It means specifying width/height should be enough for scaling. Gimp should change height/width accordingly.

In Gimp GUI it's set with the marked toggle:

enter image description here

I'm using the following line to scale images

pdb.gimp_layer_scale(visibleLayer, 435, 100, True)

Which scales the layer to specified width and height.

Couldn't another way to do it uniformly as specified above.

rok
  • 9,403
  • 17
  • 70
  • 126

2 Answers2

0

Used the following code to calculate target height to scale to and it worked.

def calculateHeight(logoLayer):
        if logoLayer.width < TARGET_LAYER_WIDTH:
            return round(logoLayer.height * (TARGET_LAYER_WIDTH * 1.0 / logoLayer.width))
        return logoLayer.height
rok
  • 9,403
  • 17
  • 70
  • 126
0

To keep the same aspect ratio, you just do some math:

newHeight = oldHeight * ( newWidth / oldWidth ) 

or in slow-motion

  • when you define a new width, this defines an enlargement factor equal to newWidth / oldWidth
  • then you apply that enlargment factor to the height using the formula above.
xenoid
  • 8,396
  • 3
  • 23
  • 49