You said your script is on a Sprite, but the
get_size() function you linked is on class Image. That's why you get the message that it's not declared in the Sprite class.
The image that the Sprite node is displaying is in its
texture property. Its type is
Texture. As you can see from the Texture doc: https://docs.godotengine.org/en/stable/classes/class_texture.html , there's a
get_size() there too.
So, to get the sprite's size, you would use