Hi!
I'm trying to implement a PHP script within Couch to allow for responsive images with different aspect ratios that don't cause the page to re-flow as they load. I understand from other posts here that pure PHP is executed before the couch tags, which is where the <cms:php> tag come in.
I've tried many different variations of below but just can't get it work, the image is never displayed. When viewing the source within the browser the image source is just: ' '.
Any help would be a huge help as the site is meant to launch this week (though this isn't a deal breaker!).
Thanks!
I'm trying to implement a PHP script within Couch to allow for responsive images with different aspect ratios that don't cause the page to re-flow as they load. I understand from other posts here that pure PHP is executed before the couch tags, which is where the <cms:php> tag come in.
I've tried many different variations of below but just can't get it work, the image is never displayed. When viewing the source within the browser the image source is just: ' '.
- Code: Select all
<div class="image-wrapper" style="max-width: <? echo $width ?>; max-height: <? echo $height ?>;">
<!-- Set the aspect % as the padding bottom -->
<div class="responsive-container" style="padding-bottom: <? echo $aspect ?>%;">
<!-- Echo the image -->
<img src="<? echo $image; ?>" alt="<cms:show k_page_title />" />
</div>
</div>
- Code: Select all
<cms:php><script>
// Reference to the image
$image = '<cms:show news_image />';
// Get the width and height
list($width, $height) = getimagesize($image);
// Calculate the aspect, with 2 decimal points
$aspect = round($height / $width * 10000) / 100;
</script></cms:php>
Any help would be a huge help as the site is meant to launch this week (though this isn't a deal breaker!).
Thanks!