function get_uniq_img_($row, $preset, $height)
{
    $imagestyle = '';
    !image_style_load($preset) ? $imagestyle = 'thumbnail' : ($imagestyle = $preset);
    $img_src = image_style_url($imagestyle, $row->field_field_blog_image[0]['rendered']['#item']['uri']);
    return "<img src=" . $img_src . " />";
}
/**
 * Add or remove styles if button is clicked
 */
function _plain_response_settings_form_submitted($form, $form_state)
{
    $styles = _plain_response_image_styles();
    if ($form_state['values']['op'] === t('Add Custom Image Styles')) {
        foreach ($styles as $part => $settings) {
            $name = 'plain_response_' . $part;
            $style = image_style_load($name);
            if (empty($style)) {
                $style = image_style_save(array('name' => $name) + $settings);
                foreach ($settings['effects'] as $effect) {
                    $effect = image_effect_save(array('isid' => $style['isid']) + $effect);
                }
            }
        }
        drupal_set_message('Custom image styles have been added.');
    }
    if ($form_state['values']['op'] === t('Remove Custom Image Styles')) {
        foreach (array_keys($styles) as $part) {
            $name = 'plain_response_' . $part;
            $style = image_style_load($name);
            if (!empty($style)) {
                image_style_delete($style);
            }
        }
        drupal_set_message('Custom image styles have been removed.');
    }
}
Beispiel #3
0
/**
 * 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);
}
$style = 'v2_big';
if (!empty($parent_node)) {
    $field_show_left_sidebar = field_get_items('node', $parent_node, 'field_show_left_sidebar');
    $show_left_sidebar = TRUE;
    if (!empty($field_show_left_sidebar[0]['value']) && $field_show_left_sidebar[0]['value'] == 'no') {
        $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'])) {
/**
 * 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>';
        }
    }
}
 /**
  * Implements Drupal\configuration\Config\Configuration::saveToActiveStore().
  */
 public function saveToActiveStore(ConfigIteratorSettings &$settings)
 {
     $style = $this->getData();
     // Does an image style with the same name already exist?
     if ($existing_style = image_style_load($this->getIdentifier())) {
         $isExistingEditable = (bool) ($existing_style['storage'] & IMAGE_STORAGE_EDITABLE);
         $isNewEditable = (bool) ($style['storage'] & IMAGE_STORAGE_EDITABLE);
         // New style is using defaults -> revert existing.
         if (!$isNewEditable && $isExistingEditable) {
             image_default_style_revert($this->getIdentifier());
         } elseif ($isExistingEditable && $isNewEditable) {
             $style['isid'] = $existing_style['isid'];
             $style = image_style_save($style);
             if (!empty($existing_style['effects'])) {
                 foreach ($existing_style['effects'] as $effect) {
                     image_effect_delete($effect);
                 }
             }
             if (!empty($style['effects'])) {
                 foreach ($style['effects'] as $effect) {
                     $effect['isid'] = $style['isid'];
                     image_effect_save($effect);
                 }
             }
         } elseif ($isNewEditable && !$isExistingEditable) {
             if (!empty($existing_style['isid'])) {
                 $style['isid'] = $existing_style['isid'];
             }
             $style = image_style_save($style);
             if (!empty($style['effects'])) {
                 foreach ($style['effects'] as $effect) {
                     $effect['isid'] = $style['isid'];
                     image_effect_save($effect);
                 }
             }
         } else {
         }
     } else {
         $style = image_style_save($style);
         if (!empty($style['effects'])) {
             foreach ($style['effects'] as $effect) {
                 $effect['isid'] = $style['isid'];
                 image_effect_save($effect);
             }
         }
         image_style_flush($style);
     }
     $settings->addInfo('imported', $this->getUniqueId());
 }
 /**
  * Returns a fully loaded input filter structure.
  *
  * @param NodeInterface $node
  * @param Context $context
  * @return bool|\stdClass
  */
 protected function loadExistingImageStyle(NodeInterface $node, Context $context)
 {
     return image_style_load($node->getName());
 }
/**
 * Implements theme_image_formatter().
 *
 * Default image for vp_contacts.
 */
function vp_theme_image_formatter($variables)
{
    $item = $variables['item'];
    $image = array('path' => $item['uri']);
    if (array_key_exists('alt', $item)) {
        $image['alt'] = $item['alt'];
    }
    if (isset($item['attributes'])) {
        $image['attributes'] = $item['attributes'];
    }
    if (isset($item['width']) && isset($item['height'])) {
        $image['width'] = $item['width'];
        $image['height'] = $item['height'];
    }
    // Do not output an empty 'title' attribute.
    if (isset($item['title']) && drupal_strlen($item['title']) > 0) {
        $image['title'] = $item['title'];
    }
    if ($variables['image_style']) {
        $image['style_name'] = $variables['image_style'];
        $output = theme('image_style', $image);
    } else {
        $output = theme('image', $image);
    }
    // Default image for vp_contacts.
    if ($variables['image_style'] === 'search_contact_thumbnail' && strpos($image['path'], 'no-profile-image') !== FALSE) {
        $style = image_style_load('search_contact_thumbnail');
        $dimensions = array();
        image_style_transform_dimensions('search_contact_thumbnail', $dimensions);
        $output = '<img src="/' . drupal_get_path('module', 'vp_contact') . '/no-profile-image_w104.png" height="' . $dimensions['height'] . '" width="' . $dimensions['width'] . '" alt="" />';
    }
    // The link path and link options are both optional, but for the options to be
    // processed, the link path must at least be an empty string.
    if (isset($variables['path']['path'])) {
        $path = $variables['path']['path'];
        $options = isset($variables['path']['options']) ? $variables['path']['options'] : array();
        // When displaying an image inside a link, the html option must be TRUE.
        $options['html'] = TRUE;
        $output = l($output, $path, $options);
    }
    return $output;
}
<?php

// Use image style machine names.
$image_styles = array('example_style_one', 'example_style_two');
foreach ($image_styles as $item) {
    // Load the style.
    $style = image_style_load($item);
    if ($style) {
        // Flush images associated with the style.
        image_style_flush($style);
        // Delete the style.
        image_style_delete($style);
    }
}
// Clear caches.
drupal_flush_all_caches();
 /**
  * Implements Drupal\configuration\Config\Configuration::saveToActiveStore().
  */
 public function saveToActiveStore(ConfigIteratorSettings &$settings)
 {
     if ($style = image_style_load($this->getIdentifier())) {
         if (!empty($style['isid'])) {
             image_style_delete($style);
         }
     }
     image_default_style_save($this->getData());
     $settings->addInfo('imported', $this->getUniqueId());
 }