froehoel
10/30/2014 - 3:15 AM

responsive imagetag

responsive imagetag

function imagetag(array $image) {
	$path 		= '/lib/images/' . $image['folder'] . '/';
	$widths		= array(400,800,1200,1600);
	$imagetag 	= NULL;
	$srcset 	= '';

	$dims = getimagesize($_SERVER['DOCUMENT_ROOT'] . $path . $image['src']);
			
	foreach($widths as $width) {
		if($dims[0] > $width) {
			$srcset .= $path . 'w' . $width . '_' . $image['src'] . ' ' . $width . 'w,';
		}
	}
	$imagetag .= '<img 
				srcset="' . $srcset . $path . $image['src'] . ' ' . $dims[0] . 'w"
				sizes= "' . $image['sizes'] . '"
				src="' . $path . $image['src'] . '" 
				alt="' . cleanstring($image['caption']) . '">';

	return $imagetag;
}