I'm trying to crop out the excess height of my image
Is there any way to achieve this, perhaps using Image
?
CodePudding user response:
This is a good example of "Godot already does that"…
Given an Image
get a rectangle with the "used" (not fully transparent) pixels:
var rect := image.get_used_rect()
And now get a new image from the one you have, cut by that rectangle:
var new_image := image.get_rect(rect)
And there you go.
If you only want to crop at the end, you can use crop
instead which does not create a new image:
image.crop(rect.end.x, rect.end.y)
Or if it is only vertically, we can do that too:
image.crop(image.get_size().x, rect.end.y)