Clean up ImageGenerator::getWidgetCode method