The gallery stores its images in the attachment system, therefore considerations for a CDN would be more of a core XF feature than a separate XFMG feature. I believe there are various suggestions related to CDN integration. There may also be add-ons that extend XF to provide CDN functionality. [bd] Attachment Store is compatible with XFMG for example.
I can't comment or provide support on that as I don't know how you have set up the CDN or how that's supposed to behave if it's part of an add-on. Obviously if it's part of an add-on, the add-on author will be better placed to provide support for that.
I was specifically referring to any CDN functionality, in case that was provided by a third party add-on. Obviously XF or XFMG can't advise you on how to set up a CDN. Aside from the config values in the code above which we provide, I can't vouch for how you are synchronising the contents of your internal_data and data directories to the CDN, nor can I advise you on how you would do that. That would be purely down to your CDN provider or CDN add-on if you have one.
That said, the configuration above only affects the URL where thumbnails and JS are served from. Attachments are served from the internal_data directory, but they are not in a directory that is publicly accessible. The attachments URL will always be yoursite/attachments/ but that URL will be accessing the files which are stored in your internal_data/attachments directory. There is a config setting to change the internal_data path, but this generally isn't going to help you in terms of serving images from an external location. That would likely require an add-on or custom development.
Can it be that the problem is that the images of XFMG be stored in a different location than all other attachments of the forum? Because those are stored oke on the CDN servers.
I'm going to see if the [ bd ] Attachment store does work in my case.