Sprintf is a way to use variables within a string easily. %d
designates a digit and %s
is any string.
So think of it like this
sprintf( '<div class="%s">%s</div>', $var1, $var2 );
So for your example, you’d need something like:
$output = sprintf( '<div class="gallery gallery-columns-%s" itemprop="image" itemscope itemtype="http://schema.org/ImageGallery">%s</div>', $columns, $output );
The only thing from your code I’m not seeing is where $columns
gets defined.