Joomgallery module has an option to wrap text (title, author, description...) but you have to specify the number of characters. This is not practical if your images have varying widths, especially if some are in landscape and others in portrait orientation. Here is how to set the output to wrap the text according to the image width.

First disable the wrapping in the module's interface, by setting the value to 0 (for title and description).

Then, in modules/mod_joomimg/helper.php, Look for the last occurence of $imgWidth. It should be in function modcontent(&$objects). Put this on a line after all if parenthesis {} are closed. The value of $imgWidth is calculated differently depending on some parameters. We need to get it after this, but before the end of the function:

$GLOBALS['largimage'] = $imgWidth;

This inserts the value in the $GLOBALS array, making it available for other functions.

Then in function rendercss(), find the line underlined below 

$css .= '.'.$csstag.'imgct {'."\n"
        . 'width:'.$containerwidth.'% !important;'."\n"
        . $csscont

And replace it with

        . 'width:'.$GLOBALS['largimage'].'px !important;'."\n"

That's it! The container now has the exact width of the image.