Alejandro Posted March 4, 2020 at 06:01 PM Share Posted March 4, 2020 at 06:01 PM Hi This came out of recent collaboration with a client. Keep in mind that right now this only works on Business and Enterprise plans. https://gist.github.com/jreviews/b03d06c8058f1043abf0bae4feafec3d You can find other dev filters and code snippets here https://gist.github.com/jreviews Enjoy! This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters Show hidden characters <?php defined('MVC_FRAMEWORK') or die; /** * Re-writes image URLs to the CloudFlare Image CDN * https://developers.cloudflare.com/images/about/ */ function jreviews_cloudflare_cdn_thumbnails ($attr, $params = []) { // Skip if thumbnails are not yet generated if ( false !== strpos($attr['src'], 'admin-ajax.php') || false !== strpos($attr['src'], 'com_jreviews') ) { return $attr; } if ( false === strpos($attr['src'], 'thumbnail') ) { return $attr; } $width = !empty($attr['width']) ? $attr['width'] : 640; $attr['src'] = str_replace(WWW_ROOT, WWW_ROOT."cdn-cgi/image/width={$width},quality=100,metadata=copyright,f=auto,fit=scale-down/", $attr['src']); // Replace '/thumbnail/' with '/original/' and remove thumbnail size $attr['src'] = preg_replace('/\/thumbnail\/[\s\S]+?\//', '/original/', $attr['src']); return $attr; } Clickfwd\Hook\Filter::add('image_attributes_before_render', 'jreviews_cloudflare_cdn_thumbnails', $priority = 5); view raw cloudflare_thumbnails.php hosted with ❤ by GitHub Josh Journey 1 Link to comment
Recommended Posts