Is there a quick way in Timber/Twig to convert images to pull from CDN?

13 Views Asked by At

I am wondering if there is a Timber function or hook where I can convert {{ post.content }} img tags to pull from our CDN instead of Wordpress. Our twig template just uses {{ post.content }} and I'd hate to rewrite a bunch of stuff if there's something out there.

For example, image tags need to look like:

<img
 srcset="
  https://xxxxxx.com/cdn-cgi/image/width=1080,quality=30/https://xxxxxx.com/[wordpress_image_path] 1080w, 
  https://xxxxxx.com/cdn-cgi/image/width=300,quality=30/https://xxxxxx.com/[wordpress_image_path] 300w, 
  https://xxxxxx.com/cdn-cgi/image/width=1024,quality=30/https://xxxxxx.com/[wordpress_image_path] 1024w,
  https://xxxxxx.com/cdn-cgi/image/width=600,quality=30/https://xxxxxx.com/[wordpress_image_path] 600w"
  src="https://xxxxxx.com/cdn-cgi/image/width=1080,quality=30/https://xxxxxx.com/[wordpress_image_path]"
  sizes="(max-width: 1080px) 100vw, 1080px"
  alt="some alt"
/>

Is there any function that exists to do this kind of conversion?

0

There are 0 best solutions below