/**
  * Overrides Drupal\configuration\Config\Configuration::getAllIdentifiers().
  */
 public static function getAllIdentifiers($component)
 {
     $identifiers = array();
     foreach (image_styles() as $key => $image_style) {
         $identifiers[$key] = $image_style['name'];
     }
     return $identifiers;
 }
Example #2
0
function hook_styles_styles()
{
    $styles = array();
    foreach (image_styles() as $style_name => $style) {
        $styles[$style_name] = $style;
    }
    return array('media' => array('image' => $styles));
}
 /**
  * Implements BeanPlugin::form().
  */
 public function form($bean, $form, &$form_state)
 {
     $form = array();
     // Show select box for the option set
     $optionsets = array();
     ctools_include('export');
     foreach (zm_template_load_all() as $name => $optionset) {
         $optionsets[$name] = check_plain($optionset->title);
     }
     $template_empty_des = '';
     if (empty($optionsets)) {
         $template_empty_des = t(' You don\'t have any template, please <a href="@href">click here</a> to create one.', array('@href' => url('admin/config/content/zm_template/add')));
     }
     $form['template'] = array('#title' => t('Template'), '#type' => 'select', '#options' => $optionsets, '#default_value' => $bean->template, '#description' => t("Chose template apply for slideshow.") . $template_empty_des);
     $image_styles = image_styles();
     $image_style_options = array();
     foreach ($image_styles as $stylename => $style) {
         $image_style_options[$stylename] = $style['label'];
     }
     $form['image_style_1'] = array('#type' => 'select', '#title' => t('Image Style 1'), '#options' => $image_style_options, '#default_value' => $bean->image_style_1, '#description' => t("Chose image style 1 apply for image field"));
     $form['image_style_2'] = array('#type' => 'select', '#title' => t('Image Style 2'), '#options' => $image_style_options, '#default_value' => $bean->image_style_2, '#description' => t("Chose image style 2 apply for image field"));
     return $form;
 }
 /**
  * Returns a list of image styles that only contain the effects we care about.
  *
  * @return \stdClass[]
  *   List of objects representing styles, ordered ascending width. Each
  *   object has the properties:
  *
  *     string   name
  *       The machine name of the style.
  *     int|null width
  *       The final width the image will be after applying the effects.
  *     int|null height
  *       The final height the image will be after applying the effects.
  *     bool     firm
  *       Whether or not the width and height can be guaranteed. Depending on
  *       the list of effects, they just be maximums.
  */
 private function getStyles()
 {
     static $styles;
     if (isset($styles)) {
         return $styles;
     }
     $styles = F\filter(image_styles(), function ($style) {
         foreach ($style['effects'] as $effect) {
             if (!in_array($effect['name'], $this->target_effects)) {
                 # Unknown effects could have unintended side-effects.
                 return false;
             }
         }
         return true;
     });
     $styles = F\map($styles, function ($style) {
         $dimensions = $this->finalDimensionsOfStyle($style);
         return (object) ['name' => $style['name'], 'width' => $dimensions->width, 'height' => $dimensions->height, 'firm' => $dimensions->firm];
     });
     uasort($styles, function ($a, $b) {
         return $a->width - $b->width;
     });
     return $styles;
 }
Example #5
0
/**
 * Define information about atom transcoders provided by a module.
 *
 * @return array $transcoder
 *   An array of atom transcoders. This array is keyed by the machine-readable
 *   transcoder name. Each transcoder is defined as an associative array
 *   containing the following item:
 *   - "title": the human-readable name of the transcoder.
 *   - "description": the longer description of the transcoder.
 *   - "formats": array of supported formats for each atom type. Currently unused.
 */
function hook_scald_transcoders()
{
    $transcoders = array();
    foreach (image_styles() as $name => $style) {
        $label = isset($style['label']) ? $style['label'] : $style['name'];
        $transcoders['style-' . $name] = array('title' => t('@style (Image style)', array('@style' => $label)), 'description' => t('Use the Image style @style to prepare the image', array('@style' => $label)), 'formats' => array('image' => 'passthrough'));
    }
    return $transcoders;
}
 /**
  * Loads a RestWS Schema object.
  *
  * @param int $id
  *   The original entity ID.
  *
  * @return stdClass
  *   An object matching the requested RestWS Schema object structure.
  */
 protected function objectLoad($id)
 {
     $object = new stdClass();
     // Get original entity.
     $original_wrapper = $this->originalWrapper($id);
     // If the wrapped entity is not of the correct bundle, bail now.
     if ($original_wrapper->getBundle() !== $this->bundleName) {
         return $object;
     }
     $original_properties = $original_wrapper->getPropertyInfo();
     // Add to our object according to our defined API property info.
     if ($map = $this->apiMap[$this->resource()]) {
         foreach (array_keys($this->propertyInfo) as $property) {
             if (array_key_exists($map[$property], $original_properties)) {
                 $value = $original_wrapper->{$map[$property]}->value(array('sanitize' => TRUE));
                 // Do some specific things for fields.
                 if ($field = field_info_field($map[$property])) {
                     // We assume the first column is the primary value column. This is
                     // how Views gets the $real_field.
                     // @see field_views_field_default_views_data()
                     $column = key($field['columns']);
                 }
                 // For now make a quick check for references, and build an array of
                 // reference objects.
                 // @todo Abstract this by creating our own format handler, using
                 //   hook_restws_format_info_alter(), which extends RestWSFormatJSON,
                 //   and overrides RestWSBaseFormat::getResourceReferenceValue.
                 if ($field && $field['type'] == 'entityreference' && ($type = $field['settings']['target_type'])) {
                     // Return an array of values, regardless of field cardinality.
                     $value = !is_array($value) ? array($value) : $value;
                     $values = array();
                     foreach ($value as $item) {
                         list($id, , $target_bundle) = entity_extract_ids($type, $item);
                         $target_resource = NULL;
                         // Get target resource from map.
                         foreach ($this->apiMap as $r => $i) {
                             if ($i['entity'] == $type && $i['bundle'] == $target_bundle) {
                                 $target_resource = $r;
                                 break;
                             }
                         }
                         $values[] = (object) array('uri' => restws_resource_uri($target_resource, $id), 'resource' => $target_resource, 'id' => $id);
                     }
                     $value = $values;
                 } elseif ($field && $field['type'] == 'image') {
                     $values = array();
                     foreach ($value as $key => $item) {
                         $values[$key] = array('alt' => $item['alt'], 'title' => $item['title'], 'mime' => $item['filemime']);
                         $values[$key]['sizes']['original'] = array('uri' => file_uri_target($item['uri']), 'height' => $item['height'], 'width' => $item['width']);
                         foreach (image_styles() as $style_name => $style) {
                             $values[$key]['sizes'][$style_name] = array('uri' => image_style_url($style_name, $item['uri']), 'height' => $style['effects'][0]['data']['height'], 'width' => $style['effects'][0]['data']['width']);
                         }
                     }
                     $value = $values;
                 } elseif ($field && is_array($value)) {
                     try {
                         $value = $original_wrapper->{$map[$property]}->{$column}->value(array('decode' => TRUE));
                     } catch (EntityMetadataWrapperException $e) {
                     }
                 }
                 $object->{$property} = $value;
             }
         }
     }
     return $object;
 }
Example #7
0
/**
* Override theme_image_style().
* Use the required image style as usual, except if a special
* imagestylename_themename style exists, in which case that style
* overrides the default.
*/
function glossy_image_style($variables) {
  global $theme;
  if (array_key_exists($variables['style_name'] . '_' . $theme, image_styles())) {
    $variables['style_name'] = $variables['style_name'] . '_' . $theme;
  }

  // Starting with Drupal 7.9, the width and height attributes are
  // added to the img tag. Adding the if clause to conserve
  // compatibility with Drupal < 7.9
  if (function_exists('image_style_transform_dimensions')) {
    // Determine the dimensions of the styled image.
    $dimensions = array(
      'width' => $variables['width'],
      'height' => $variables['height'],
    );

    image_style_transform_dimensions($variables['style_name'], $dimensions);

    $variables['width'] = $dimensions['width'];
    $variables['height'] = $dimensions['height'];
  }

  $variables['path'] = image_style_url($variables['style_name'], $variables['path']);
  return theme('image', $variables);
}
Example #8
0
function delete_all_thumbnail_of_collection($nid)
{
    $all_styles = array_keys(image_styles());
    foreach ($all_styles as $style) {
        delete_thumbnail_of_collection($nid, $style);
    }
}