How can I render object to fit image precisely?

I need to render a cube the way that output image is cropped to cube and has as less unused space as possible. I know I can set up camera and place it carefully so only cube will be on rendered image without blank space. But is there some render option like “crop rendered image to selected object” or “fit camera resolution to selected object”?

There isn’t a built-in function for that , but this addon looks close to what you need :