Skip to content

Instantly share code, notes, and snippets.

@pau1m
Created February 12, 2013 17:25
Show Gist options
  • Select an option

  • Save pau1m/4771520 to your computer and use it in GitHub Desktop.

Select an option

Save pau1m/4771520 to your computer and use it in GitHub Desktop.
Quick hack to help get multiple image info in services / views
/*
*
*@param int $nid
*A node nid
*@param string $image_field
*Name of field on which to find images
*
*@return array
*Urls for various sizes of image
*/
function cas_views_helper_image($nid = null, $image_field = null){
if (empty($nid) || empty($image_field)){
return "";
}
//should probs use entity field query. d6 style ftw :p
$node = node_load($nid);
$styles = array_keys(image_styles());
for ($i=0; $i < count($node->{$image_field}[LANGUAGE_NONE]); $i++){
foreach ($styles as $style){
$orig_full_path = image_style_url($style, $node->{$image_field}[LANGUAGE_NONE][$i]['uri']);
$default_uri = str_replace($GLOBALS['base_url'].'/sites/default/files/','public://', $orig_full_path);
$images[$i][$style] = image_get_info($default_uri);
$images[$i][$style]['uri'] = $default_uri;
}
}
return $images;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment