function cstark_preprocess_node(&$variables) { if (user_access('administer nodes')) { $variables['edit_link'] = l(t('Edit'), 'node/' . $variables['nid'] . '/edit'); if ($variables['type'] == 'painting') { $title = $variables['promote'] ? t('Remove from front page') : t('Add to front page'); $variables['set_as_main_link'] = l($title, 'set-as-main/' . $variables['nid']); // Facebook share. $url = url('node/' . $variables['nid'], array('absolute' => TRUE)); $variables['share_link'] = l(t('Share'), "http://www.facebook.com/sharer.php?u={$url}", array('attributes' => array('class' => array('facebook')))); } } if ($variables['type'] == 'painting') { $wrapper = entity_metadata_wrapper('node', $variables['nid']); if ($image = $wrapper->field_image->value()) { $element = array('#tag' => 'meta', '#attributes' => array('property' => 'og:image', 'content' => file_create_url($image['uri']))); drupal_add_html_head($element, 'cstark_painting_image'); $element = array('#tag' => 'meta', '#attributes' => array('property' => 'og:title', 'content' => $wrapper->label())); drupal_add_html_head($element, 'cstark_painting_title'); } } if ($variables['type'] == 'painting' && !drupal_is_front_page()) { $variables['pager'] = shapira_get_painting_pager($variables['nid']); } if ($variables['type'] != 'news') { $variables['hide_title'] = true; } if ($variables['type'] == 'painting') { if ($variables['field_image']) { $info = image_get_info(image_style_path('painting', $variables['field_image'][0]['uri'])); $variables['node_width'] = $info['width']; } } }
/** * Source https://api.drupal.org/api/drupal/modules%21image%21image.module/function/theme_image_style/7.x * * Usage is the same as theme_image_style. * * @param $variables */ function adminlte_image_style($variables) { $styled_path = image_style_path($variables['style_name'], $variables['path']); if (!file_exists($styled_path)) { $style = image_style_load($variables['style_name']); image_style_create_derivative($style, $variables['path'], $styled_path); } $variables['path'] = $styled_path; return theme('image', $variables); }
</ul> </section> </div> </div> <?php } else { ?> <?php foreach ($items as $delta => $item) { ?> <?php if (module_exists('colorbox')) { if (!empty($settings['destination_image_style'])) { $img_url = image_style_path($settings['destination_image_style'], $item['uri']); } else { $img_url = file_create_url($item['uri']); } } $link_icon = ''; $gallery_id = !empty($node->nid) ? $node->nid : $item['timestamp']; $href = ''; if (!empty($img_url)) { $href = 'rel="gallery[' . $gallery_id . ']" class="colorbox" href="' . $img_url . '"'; $link_icon = '<div class="hovercover"><div class="hovericon"><i class="hoverzoom"></i></div></div>'; } ?> <div class="image"><figure class="post-img media"> <div class="mediaholder"> <a <?php
$show_left_sidebar = FALSE; } if ($show_left_sidebar) { $style = 'v2_big'; } else { $style = 'v2_article_large'; } } $field_main_image = field_get_items('node', $node, 'field_main_image'); $image_style = image_style_load($style); $width = '100%'; $height = '100%'; $w = array(); $h = array(); //$path = file_create_url($field_main_image[0]['uri']); $path = image_style_path($style, $field_main_image[0]['uri']); $image_info = image_get_info($path); if (!empty($image_info['width'])) { $w[] = (int) $image_info['width']; } if (!empty($image_info['height'])) { $h[] = (int) $image_info['height']; } foreach ($image_style['effects'] as $effect) { if (!empty($effect['data']['width'])) { $w[] = (int) $effect['data']['width']; } if (!empty($effect['data']['height'])) { $h[] = (int) $effect['data']['height']; } }
/** * Implements theme_preprocess_node(). */ function cuemail_preprocess_node(&$vars) { $vars['theme_hook_suggestions'][] = 'node__' . $vars['type'] . '__' . $vars['view_mode']; $url = url('node/' . $vars['nid'], array('absolute' => TRUE, 'alias' => TRUE, 'https' => FALSE)); $vars['node_url'] = $url; if ($vars['type'] == 'newsletter') { if (!empty($vars['content']['field_newsletter_intro_image'])) { $vars['content']['field_newsletter_intro_image'][0]['#image_style'] = 'email_medium'; } $list = array(); foreach ($vars['content']['field_newsletter_section']['#items'] as $key => $item) { $key_2 = key($vars['content']['field_newsletter_section'][$key]['entity']['field_collection_item']); $articles = $vars['content']['field_newsletter_section'][$key]['entity']['field_collection_item'][$key_2]['field_newsletter_articles']['#items']; foreach ($articles as $article) { $node = node_load($article['target_id']); $list[] = $node->title; } } $newsletter_logo_image_style_uri = image_style_path('medium', $vars['newsletter_logo_uri']); if (!file_exists($newsletter_logo_image_style_uri)) { image_style_create_derivative(image_style_load('medium'), $vars['newsletter_logo_uri'], $newsletter_logo_image_style_uri); } $image_info = image_get_info($newsletter_logo_image_style_uri); $vars['newsletter_logo_width'] = round($image_info['width'] * 0.46333); $vars['newsletter_logo_height'] = round($image_info['height'] * 0.46333); $vars['content']['list'] = theme('item_list', array('items' => $list, 'type' => 'ul', 'attributes' => array('class' => array('bullet-list')))); } if ($vars['type'] == 'article') { if (!empty($vars['content']['field_article_thumbnail'][0])) { $vars['content']['field_article_thumbnail'][0]['#path']['options']['absolute'] = TRUE; } if ($vars['view_mode'] == 'email_feature') { $vars['content']['field_article_thumbnail'][0]['#image_style'] = 'email_feature_thumbnail'; } if (isset($vars['field_article_categories'])) { foreach ($vars['field_article_categories'] as $tid) { if (isset($tid['tid'])) { $tids[] = $tid['tid']; } } } if (isset($tids)) { $terms = taxonomy_term_load_multiple($tids); foreach ($terms as $term) { if (isset($term->name)) { $tag = $term->name; if ($term->field_category_display[LANGUAGE_NONE][0]['value'] == 'show') { if (!empty($term->field_category_term_page_link)) { $new_tags[] = l($tag, $term->field_category_term_page_link[LANGUAGE_NONE][0]['url'], array('absolute' => TRUE, 'alias' => TRUE, 'https' => FALSE)); } else { $new_tags[] = $tag; } } } } $markup = implode(' ', $new_tags); unset($vars['content']['field_article_categories']); $vars['content']['field_article_categories'][0]['#markup'] = '<p>' . $markup . '</p>'; } } }
/** * Additional comment variables */ function marinelli_preprocess_comment(&$vars) { $vars['classes_array'][] = $vars['zebra']; $user_image = array('width' => 0); if (isset($vars['user']->picture)) { // No.. I don't use style if (!variable_get('user_picture_style')) { $size = variable_get('user_picture_dimensions'); $size = explode('x', $size); $user_image['width'] = $size[0]; } else { //Yes... I use style if ($picture = file_load($vars['comment']->picture->fid)) { $user_image = image_get_info(image_style_path(variable_get('user_picture_style'), $picture->uri)); } } } $vars['image_width'] = $user_image['width'] + 25; }
function delete_thumbnail_of_collection($nid, $image_style) { $targets = get_store_of_collection($nid); $public = $targets[3]; $public0 = $targets[4]; $the_public_thumb = drupal_realpath(image_style_path($image_style, $public)); // thumbnail path $the_public0_thumb = drupal_realpath(image_style_path($image_style, $public0)); // thumbnail path // delete thumbs of public/$store if (file_exists($the_public_thumb)) { if (!is_dir($the_public_thumb) || !($the_public_thumb_handler = opendir($the_public_thumb))) { throw new Exception("delete_thumbnail_of_collection(): cannot read {$the_public_thumb}."); } while (($fname = readdir($the_public_thumb_handler)) !== false) { if (is_file_of_collection($fname, $nid)) { unlink($the_public_thumb . '/' . $fname); } } } // delete thumbs of public0/$store if (file_exists($the_public0_thumb)) { if (!is_dir($the_public0_thumb) || !($the_public0_thumb_handler = opendir($the_public0_thumb))) { throw new Exception("delete_thumbnail_of_collection(): cannot read {$the_public0_thumb}."); } while (($fname = readdir($the_public0_thumb_handler)) !== false) { if (is_file_of_collection($fname, $nid)) { unlink($the_public0_thumb . '/' . $fname); } } } }
<?php foreach ($items as $delta => $item) { ?> <li data-thumb="<?php print file_create_url(image_style_path('hauptbild', $item['#item']['uri'])); ?> "> <a href="<?php print file_create_url($item['#item']['uri']); ?> " class="lightbox"> <?php print render($item); ?> </a> </li> <?php } ?>
function bartik_image_style($variables) { $style_name = $variables['style_name']; $path = $variables['path']; // theme_image() can only honor the $getsize parameter with local file paths. // The derivative image is not created until it has been requested so the file // may not yet exist, in this case we just fallback to the URL. $style_path = image_style_path($style_name, $path); if (!file_exists($style_path)) { $style_path = image_style_url($style_name, $path); } $variables['path'] = $style_path; if (is_file($style_path)) { if (list($width, $height, $type, $attributes) = @getimagesize($style_path)) { $variables['width'] = $width; $variables['height'] = $height; } } $variables['attributes'] = array("style" => "max-width: 100%; height:auto;"); return theme('image', $variables); }