简体   繁体   中英

Scale image layer uniformly using python-fu in Gimp

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:

在此处输入图片说明

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.

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM