Center Align and Image inside a Widget

Sorry for the newbie question. I was watching how to create a widget that loads an image from a url. When I try to do this in the large widget, the image is aligned left leaving a bunch of black space on the right side of the widget. Is there a way to align the image in the center of the widget?

I tried:
widget.centerAlignImage();

But this gives an error saying the function doesn’t exist.

Never mind. I figured it out.

widget.addImage(img).centerAlignImage();

This works.