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
newWidth / oldWidth
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.