Hello fellow druaplistas!
I have a situation where I need to output an image field using different image styles depending on some checkbox settings.
I'm doing this inside a node template. Basically this goes like this:
if ($layout == 1) {
print $small_image;
}
if ($layout == 2 {
print $medium_image;
}
To get the url to the correct sized image I can use image_style_url
, but this way I have to build the links to the bigger version to open inside colorbox manually.
Is there some function available that I can pass two image styles and it uses them to generate an image tag wrapped with a link to the bigger sized image?
Update: I took Clive's code (thanks again) and added a second parameter to be able to choose the preset that will be shown inside the colobox. Also Title and Alt is now included: As your code was better than mine I took it and extended the stuff I needed, maybe it's of use for someone:
function _colorbox_link($image, $style_name, $style_name_link = 'colorbox_full') {
$image_style = theme('image_style', array(
'style_name' => $style_name,
'path' => $image['uri'],
'alt' => $image['alt'],
'title' => $image['title']
));
$url = image_style_url($style_name_link, $image['uri']);
$link = l($image_style, $url, array(
'html' => TRUE,
'attributes' => array(
'rel' => array('colorbox-gallery'),
'class' => array('colorbox')
)
));
return $link;
}