You can use the following snippet and adjust to your needs in order to allow the images to be loaded via your CDN.
Insert this code on to your theme functions.php
function svi_cdn_image_url($image, $attachment_id, $size, $icon)
{
$url = $image[0];
$types = ["gif", "png", "jpg"];
$type = substr($url, -3);
if (in_array($type, $types)) {
$site = get_site_url();
$cdn = "{Insert cdn url here}";
$image[0] = str_replace($site, $cdn, $url);
}
return $url;
}
add_filter('wp_get_attachment_image_src', 'svi_cdn_image_url');