本文整理汇总了PHP中Drupal\image\Entity\ImageStyle::load方法的典型用法代码示例。如果您正苦于以下问题:PHP ImageStyle::load方法的具体用法?PHP ImageStyle::load怎么用?PHP ImageStyle::load使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\image\Entity\ImageStyle
的用法示例。
在下文中一共展示了ImageStyle::load方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: build
/**
* {@inheritdoc}
*/
public function build()
{
$query = \Drupal::entityQuery('node')->condition('status', 1)->condition('type', 'team_member')->sort('field_order', 'ASC');
$nids = $query->execute();
$nodes = node_load_multiple($nids);
//$nodes = entity_load_multiple('node', $nids);
$ind = 1;
$output = '<div class="tabbable tabs-left tabcordion">
<ul class="nav nav-tabs">';
foreach ($nodes as $node) {
$class = $ind == 1 ? 'active' : '';
$output .= '<li class="' . $class . '"><a data-target="#team_member_tab' . $ind . '" data-toggle="tab">' . $node->title->value . '<span>' . $node->get('field_designation')->value . '</span></a></li>';
$ind++;
}
$ind = 1;
$output .= '</ul>
<div class="tab-content">';
foreach ($nodes as $node) {
$class = $ind == 1 ? 'active' : '';
if (is_object($node->field_image->entity)) {
$path = $node->field_image->entity->getFileUri();
$url = ImageStyle::load('person_picture')->buildUrl($path);
$tab_content_html = '<div class="row"><div class="col-md-3"><img src="' . $url . '" alt=""></div><div class="col-md-9">' . $node->get('body')->value . '</div> </div>';
} else {
$tab_content_html = '<div>' . $node->get('body')->value . '</div>';
}
$output .= '<div class="tab-pane ' . $class . '" id="team_member_tab' . $ind . '"> ' . $tab_content_html . ' </div>';
$ind++;
}
$output .= '</div>
</div>';
return array('#type' => 'markup', '#markup' => $output, '#attached' => array('library' => array('barney_river_utilities/tabcordion', 'barney_river_utilities/tabcordion_hook')));
}
示例2: testPictureOnNodeComment
/**
* Tests embedded users on node pages.
*/
function testPictureOnNodeComment()
{
$this->drupalLogin($this->webUser);
// Save a new picture.
$image = current($this->drupalGetTestFiles('image'));
$file = $this->saveUserPicture($image);
$node = $this->drupalCreateNode(array('type' => 'article'));
// Enable user pictures on nodes.
$this->config('system.theme.global')->set('features.node_user_picture', TRUE)->save();
$image_style_id = $this->config('core.entity_view_display.user.user.compact')->get('content.user_picture.settings.image_style');
$style = ImageStyle::load($image_style_id);
$image_url = $style->buildUrl($file->getfileUri());
$alt_text = 'Profile picture for user ' . $this->webUser->getUsername();
// Verify that the image is displayed on the node page.
$this->drupalGet('node/' . $node->id());
$elements = $this->cssSelect('.node__meta .field--name-user-picture img[alt="' . $alt_text . '"][src="' . $image_url . '"]');
$this->assertEqual(count($elements), 1, 'User picture with alt text found on node page.');
// Enable user pictures on comments, instead of nodes.
$this->config('system.theme.global')->set('features.node_user_picture', FALSE)->set('features.comment_user_picture', TRUE)->save();
$edit = array('comment_body[0][value]' => $this->randomString());
$this->drupalPostForm('comment/reply/node/' . $node->id() . '/comment', $edit, t('Save'));
$elements = $this->cssSelect('.comment__meta .field--name-user-picture img[alt="' . $alt_text . '"][src="' . $image_url . '"]');
$this->assertEqual(count($elements), 1, 'User picture with alt text found on the comment.');
// Disable user pictures on comments and nodes.
$this->config('system.theme.global')->set('features.node_user_picture', FALSE)->set('features.comment_user_picture', FALSE)->save();
$this->drupalGet('node/' . $node->id());
$this->assertNoRaw(file_uri_target($file->getFileUri()), 'User picture not found on node and comment.');
}
示例3: viewElements
/**
* {@inheritdoc}
*/
public function viewElements(FieldItemListInterface $items, $langcode)
{
$elements = array();
$files = $this->getEntitiesToView($items, $langcode);
// Early opt-out if the field is empty.
if (empty($files)) {
return $elements;
}
$image_style_setting = $this->getSetting('image_style');
// Determine if Image style is required.
$image_style = NULL;
if (!empty($image_style_setting)) {
$image_style = entity_load('image_style', $image_style_setting);
}
foreach ($files as $delta => $file) {
$image_uri = $file->getFileUri();
// Get image style URL
if ($image_style) {
$image_uri = ImageStyle::load($image_style->getName())->buildUrl($image_uri);
} else {
// Get absolute path for original image
$image_uri = $file->url();
}
$elements[$delta] = array('#markup' => $image_uri);
}
return $elements;
}
示例4: doTestWatermarkOperations
/**
* Watermark operations test.
*/
public function doTestWatermarkOperations()
{
$image_factory = $this->container->get('image.factory');
$test_file = drupal_get_path('module', 'simpletest') . '/files/image-1.png';
$original_uri = file_unmanaged_copy($test_file, 'public://', FILE_EXISTS_RENAME);
$generated_uri = 'public://styles/image_effects_test/public/' . \Drupal::service('file_system')->basename($original_uri);
$watermark_file = drupal_get_path('module', 'simpletest') . '/files/image-test.png';
$watermark_uri = file_unmanaged_copy($watermark_file, 'public://', FILE_EXISTS_RENAME);
$effect = ['id' => 'image_effects_watermark', 'data' => ['placement' => 'left-top', 'x_offset' => 1, 'y_offset' => 1, 'opacity' => 100, 'watermark_image' => $watermark_uri]];
$uuid = $this->addEffectToTestStyle($effect);
// Load Image Style.
$image_style = ImageStyle::load('image_effects_test');
// Check that ::applyEffect generates image with expected watermark.
$image_style->createDerivative($original_uri, $image_style->buildUri($original_uri));
$image = $image_factory->get($generated_uri, 'gd');
$watermark = $image_factory->get($watermark_uri, 'gd');
$this->assertFalse($this->colorsAreEqual($this->getPixelColor($watermark, 0, 0), $this->getPixelColor($image, 0, 0)));
$this->assertTrue($this->colorsAreEqual($this->getPixelColor($watermark, 0, 0), $this->getPixelColor($image, 1, 1)));
$this->assertTrue($this->colorsAreEqual($this->getPixelColor($watermark, 0, 1), $this->getPixelColor($image, 1, 2)));
$this->assertTrue($this->colorsAreEqual($this->getPixelColor($watermark, 0, 3), $this->getPixelColor($image, 1, 4)));
// Remove effect.
$this->removeEffectFromTestStyle($uuid);
// Test for watermark PNG image with full transparency set, 100% opacity
// watermark.
$test_file = drupal_get_path('module', 'image_effects') . '/tests/images/fuchsia.png';
$original_uri = file_unmanaged_copy($test_file, 'public://', FILE_EXISTS_RENAME);
$generated_uri = 'public://styles/image_effects_test/public/' . \Drupal::service('file_system')->basename($original_uri);
$watermark_file = drupal_get_path('module', 'simpletest') . '/files/image-test.png';
$watermark_uri = file_unmanaged_copy($watermark_file, 'public://', FILE_EXISTS_RENAME);
$effect = ['id' => 'image_effects_watermark', 'data' => ['placement' => 'left-top', 'x_offset' => 0, 'y_offset' => 0, 'opacity' => 100, 'watermark_image' => $watermark_uri]];
$uuid = $this->addEffectToTestStyle($effect);
// Load Image Style.
$image_style = ImageStyle::load('image_effects_test');
// Check that ::applyEffect generates image with expected transparency.
$image_style->createDerivative($original_uri, $image_style->buildUri($original_uri));
$image = $image_factory->get($generated_uri, 'gd');
$this->assertTrue($this->colorsAreEqual($this->getPixelColor($image, 0, 19), $this->fuchsia));
// Remove effect.
$this->removeEffectFromTestStyle($uuid);
// Test for watermark PNG image with full transparency set, 50% opacity
// watermark.
$test_file = drupal_get_path('module', 'image_effects') . '/tests/images/fuchsia.png';
$original_uri = file_unmanaged_copy($test_file, 'public://', FILE_EXISTS_RENAME);
$generated_uri = 'public://styles/image_effects_test/public/' . \Drupal::service('file_system')->basename($original_uri);
$watermark_file = drupal_get_path('module', 'simpletest') . '/files/image-test.png';
$watermark_uri = file_unmanaged_copy($watermark_file, 'public://', FILE_EXISTS_RENAME);
$effect = ['id' => 'image_effects_watermark', 'data' => ['placement' => 'left-top', 'x_offset' => 0, 'y_offset' => 0, 'opacity' => 50, 'watermark_image' => $watermark_uri]];
$uuid = $this->addEffectToTestStyle($effect);
// Load Image Style.
$image_style = ImageStyle::load('image_effects_test');
// Check that ::applyEffect generates image with expected alpha.
$image_style->createDerivative($original_uri, $image_style->buildUri($original_uri));
$image = $image_factory->get($generated_uri, 'gd');
$this->assertTrue($this->colorsAreEqual($this->getPixelColor($image, 0, 19), $this->fuchsia));
// GD and ImageMagick return slightly different colors, use the
// ::colorsAreClose method.
$this->assertTrue($this->colorsAreClose($this->getPixelColor($image, 39, 0), [127, 127, 127, 0]));
// Remove effect.
$this->removeEffectFromTestStyle($uuid);
}
示例5: viewElements
/**
* {@inheritdoc}
*/
public function viewElements(FieldItemListInterface $items, $langcode)
{
$elements = [];
$thumb_image_style = $this->getSetting('thumbnail_image_style');
$popup_image_style = $this->getSetting('popup_image_style');
$gallery_type = $this->getSetting('gallery_type');
$files = $this->getEntitiesToView($items, $langcode);
foreach ($files as $delta => $file) {
$image_uri = $file->getFileUri();
$popup_image_path = !empty($popup_image_style) ? ImageStyle::load($popup_image_style)->buildUrl($image_uri) : $image_uri;
// Depending on the outcome of https://www.drupal.org/node/2622586,
// Either a class will need to be added to the $url object,
// Or a custom theme function might be needed to do so.
// For the time being, 'a' is used as the delegate in magnific-popup.js.
$url = Url::fromUri(file_create_url($popup_image_path));
$item = $file->_referringItem;
$item_attributes = $file->_attributes;
unset($file->_attributes);
$item_attributes['class'][] = 'mfp-thumbnail';
if ($gallery_type === 'first_item' && $delta > 0) {
$elements[$delta] = ['#theme' => 'image_formatter', '#url' => $url, '#attached' => ['library' => ['magnific_popup/magnific_popup']]];
} else {
$elements[$delta] = ['#theme' => 'image_formatter', '#item' => $item, '#item_attributes' => $item_attributes, '#image_style' => $thumb_image_style, '#url' => $url, '#attached' => ['library' => ['magnific_popup/magnific_popup']]];
}
}
return $elements;
}
示例6: doTestColorshiftOperations
/**
* Color Shift operations test.
*/
public function doTestColorshiftOperations()
{
$image_factory = $this->container->get('image.factory');
// Test on the PNG test image.
$test_file = drupal_get_path('module', 'simpletest') . '/files/image-test.png';
$original_uri = file_unmanaged_copy($test_file, 'public://', FILE_EXISTS_RENAME);
$generated_uri = 'public://styles/image_effects_test/public/' . \Drupal::service('file_system')->basename($original_uri);
// Test data.
$test_data = ['#FF0000' => [$this->red, $this->yellow, $this->transparent, $this->fuchsia], '#00FF00' => [$this->yellow, $this->green, $this->transparent, $this->cyan], '#0000FF' => [$this->fuchsia, $this->cyan, $this->transparent, $this->blue], '#929BEF' => [[255, 155, 239, 0], [146, 255, 239, 0], $this->transparent, [146, 155, 255, 0]]];
foreach ($test_data as $key => $colors) {
// Add Color Shift effect to the test image style.
$effect = ['id' => 'image_effects_color_shift', 'data' => ['RGB][hex' => $key]];
$uuid = $this->addEffectToTestStyle($effect);
// Load Image Style.
$image_style = ImageStyle::load('image_effects_test');
// Check that ::applyEffect generates image with expected color shift.
$image_style->createDerivative($original_uri, $image_style->buildUri($original_uri));
$image = $image_factory->get($generated_uri, 'gd');
$this->assertTrue($this->colorsAreEqual($colors[0], $this->getPixelColor($image, 0, 0)));
$this->assertTrue($this->colorsAreEqual($colors[1], $this->getPixelColor($image, 39, 0)));
$this->assertTrue($this->colorsAreEqual($colors[2], $this->getPixelColor($image, 0, 19)));
$this->assertTrue($this->colorsAreEqual($colors[3], $this->getPixelColor($image, 39, 19)));
// Remove effect.
$uuid = $this->removeEffectFromTestStyle($uuid);
}
}
示例7: doTestAutoOrientOperations
/**
* Auto Orientation operations test.
*/
public function doTestAutoOrientOperations()
{
$image_factory = $this->container->get('image.factory');
$test_data = [['test_file' => drupal_get_path('module', 'image_effects') . '/misc/portrait-painting.jpg', 'original_width' => 640, 'original_height' => 480, 'derivative_width' => 200, 'derivative_height' => 267], ['test_file' => drupal_get_path('module', 'simpletest') . '/files/image-test.jpg', 'original_width' => 40, 'original_height' => 20, 'derivative_width' => 200, 'derivative_height' => 100], ['test_file' => drupal_get_path('module', 'simpletest') . '/files/image-1.png', 'original_width' => 360, 'original_height' => 240, 'derivative_width' => 200, 'derivative_height' => 133]];
foreach ($test_data as $data) {
// Get expected URIs.
$original_uri = file_unmanaged_copy($data['test_file'], 'public://', FILE_EXISTS_RENAME);
$generated_uri = 'public://styles/image_effects_test/public/' . \Drupal::service('file_system')->basename($original_uri);
// Test source image dimensions.
$image = $image_factory->get($original_uri);
$this->assertEqual($data['original_width'], $image->getWidth());
$this->assertEqual($data['original_height'], $image->getHeight());
// Load Image Style and get expected derivative URL.
$image_style = ImageStyle::load('image_effects_test');
$url = file_url_transform_relative($image_style->buildUrl($original_uri));
// Check that ::transformDimensions returns expected dimensions.
$variables = array('#theme' => 'image_style', '#style_name' => 'image_effects_test', '#uri' => $original_uri, '#width' => $image->getWidth(), '#height' => $image->getHeight());
$this->assertEqual('<img src="' . $url . '" width="' . $data['derivative_width'] . '" height="' . $data['derivative_height'] . '" alt="" class="image-style-image-effects-test" />', $this->getImageTag($variables));
// Check that ::applyEffect generates image with expected dimensions.
$image_style->createDerivative($original_uri, $image_style->buildUri($original_uri));
$image = $image_factory->get($generated_uri);
$this->assertEqual($data['derivative_width'], $image->getWidth());
$this->assertEqual($data['derivative_height'], $image->getHeight());
}
}
示例8: transformDimensions
/**
* {@inheritdoc}
*/
public function transformDimensions(array &$dimensions, $uri)
{
if (!isset($dimensions['width']) || !isset($dimensions['height'])) {
// We cannot know which preset would be executed and thus cannot know the
// resulting dimensions, unless both styles return the same dimensions:
$landscape_dimensions = $portrait_dimensions = $dimensions;
/* @var ImageStyle $landscape_style */
$landscape_style = ImageStyle::load($this->configuration['landscape']);
$landscape_style->transformDimensions($landscape_dimensions, $uri);
/* @var ImageStyle $portrait_style */
$portrait_style = ImageStyle::load($this->configuration['portrait']);
$portrait_style->transformDimensions($portrait_dimensions, $uri);
if ($landscape_dimensions == $portrait_dimensions) {
$dimensions = $landscape_dimensions;
} else {
$dimensions['width'] = $dimensions['height'] = NULL;
}
} else {
$ratio_adjustment = isset($this->configuration['ratio_adjustment']) ? floatval($this->configuration['ratio_adjustment']) : 1;
$aspect = $dimensions['width'] / $dimensions['height'];
$style_name = $aspect * $ratio_adjustment > 1 ? $this->configuration['landscape'] : $this->configuration['portrait'];
/* @var ImageStyle $style */
$style = ImageStyle::load($style_name);
$style->transformDimensions($dimensions, $uri);
}
}
示例9: doTestContrastOperations
/**
* Contrast operations test.
*/
public function doTestContrastOperations()
{
$image_factory = $this->container->get('image.factory');
$image_toolkit_id = $image_factory->getToolkitId();
// Test on the PNG test image.
$test_file = drupal_get_path('module', 'simpletest') . '/files/image-test.png';
$original_uri = file_unmanaged_copy($test_file, 'public://', FILE_EXISTS_RENAME);
$generated_uri = 'public://styles/image_effects_test/public/' . \Drupal::service('file_system')->basename($original_uri);
// Test data.
$test_data = ['0' => [$this->red, $this->green, $this->transparent, $this->blue], '-50' => [$image_toolkit_id === 'imagemagick' ? array(180, 75, 75, 0) : array(159, 95, 95, 0), $image_toolkit_id === 'imagemagick' ? array(75, 180, 75, 0) : array(95, 159, 95, 0), $this->transparent, $image_toolkit_id === 'imagemagick' ? array(75, 75, 180, 0) : array(95, 95, 159, 0)], '-100' => [$image_toolkit_id === 'imagemagick' ? array(128, 128, 128, 0) : array(127, 127, 127, 0), $image_toolkit_id === 'imagemagick' ? array(128, 128, 128, 0) : array(127, 127, 127, 0), $this->transparent, $image_toolkit_id === 'imagemagick' ? array(128, 128, 128, 0) : array(127, 127, 127, 0)], '50' => [array(255, 0, 0, 0), array(0, 255, 0, 0), $this->transparent, array(0, 0, 255, 0)], '100' => [array(255, 0, 0, 0), array(0, 255, 0, 0), $this->transparent, array(0, 0, 255, 0)]];
foreach ($test_data as $key => $colors) {
// Add contrast effect to the test image style.
$effect = ['id' => 'image_effects_contrast', 'data' => ['level' => $key]];
$uuid = $this->addEffectToTestStyle($effect);
// Load Image Style.
$image_style = ImageStyle::load('image_effects_test');
// Check that ::applyEffect generates image with expected contrast.
$image_style->createDerivative($original_uri, $image_style->buildUri($original_uri));
$image = $image_factory->get($generated_uri, 'gd');
$this->assertTrue($this->colorsAreEqual($colors[0], $this->getPixelColor($image, 0, 0)));
$this->assertTrue($this->colorsAreEqual($colors[1], $this->getPixelColor($image, 39, 0)));
$this->assertTrue($this->colorsAreEqual($colors[2], $this->getPixelColor($image, 0, 19)));
$this->assertTrue($this->colorsAreEqual($colors[3], $this->getPixelColor($image, 39, 19)));
// Remove effect.
$uuid = $this->removeEffectFromTestStyle($uuid);
}
}
示例10: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state, $grouping = NULL)
{
// Load logo image.
$rendered_image = NULL;
if (!empty($grouping->logo_fid)) {
$file = File::load($grouping->logo_fid);
if ($file) {
$logo_url = ImageStyle::load('ea_groupings_200x200')->buildUrl($file->getFileUri());
$image_array = array('#theme' => 'image', '#uri' => $logo_url, '#alt' => $this->t('Logo for @grouping', array('@grouping' => $grouping->title)), '#title' => $this->t('@grouping', array('@grouping' => $grouping->title)));
$rendered_image = \Drupal::service('renderer')->render($image_array);
}
}
// Construct form.
$form = array();
$form['gid'] = array('#type' => 'value', '#value' => $grouping->gid);
$form['add'] = array('#type' => 'fieldset', '#description' => $this->t('Update grouping'), '#title' => $this->t('Edit grouping'));
$form['add']['title'] = array('#type' => 'textfield', '#title' => $this->t('Title'), '#description' => $this->t('Title of grouping'), '#size' => 20, '#maxlength' => 20, '#required' => FALSE, '#default_value' => $grouping->title);
$form['add']['description'] = array('#type' => 'textarea', '#title' => $this->t('Description'), '#description' => $this->t('A short description of the grouping'), '#required' => FALSE, '#default_value' => $grouping->description);
$form['add']['logo'] = array('#type' => 'markup', '#markup' => $rendered_image);
$form['add']['logo_fid'] = array('#title' => $this->t('Update logo'), '#type' => 'managed_file', '#description' => $this->t('Upload a logo for the grouping'), '#default_value' => NULL, '#upload_location' => 'public://logos/');
$form['add']['time_zone'] = array('#title' => $this->t('Timezone'), '#type' => 'select', '#description' => $this->t('Select a time zone for the grouping'), '#options' => _ea_groupings_get_time_zones(), '#default_value' => $grouping->time_zone);
$form['add']['parent_gid'] = array('#type' => 'select', '#description' => $this->t('Select a parent grouping'), '#options' => _ea_groupings_get_groupings_list(FALSE, $grouping->gid), '#disabled' => _ea_groupings_is_parent($grouping->gid), '#default_value' => $grouping->parent_gid);
$form['add']['submit'] = array('#type' => 'submit', '#name' => 'add_group', '#value' => $this->t('Update grouping'), '#weight' => 100);
$form['add']['old_title'] = array('#type' => 'value', '#value' => $grouping->title);
$form['add']['old_logo_fid'] = array('#type' => 'value', '#value' => $grouping->logo_fid);
$form['add']['old_parent_gid'] = array('#type' => 'value', '#value' => $grouping->parent_gid);
return $form;
}
示例11: renderThumbnail
/**
* {@inheritdoc}
*/
public function renderThumbnail($image_style, $link_url)
{
$this->downloadThumbnail();
$output = ['#theme' => 'image', '#uri' => !empty($image_style) ? ImageStyle::load($image_style)->buildUrl($this->getLocalThumbnailUri()) : $this->getLocalThumbnailUri()];
if ($link_url) {
$output = ['#type' => 'link', '#title' => $output, '#url' => $link_url];
}
return $output;
}
示例12: doTestSetCanvasOperations
/**
* Set canvas operations test.
*/
public function doTestSetCanvasOperations()
{
$image_factory = $this->container->get('image.factory');
$test_file = drupal_get_path('module', 'simpletest') . '/files/image-test.png';
$original_uri = file_unmanaged_copy($test_file, 'public://', FILE_EXISTS_RENAME);
$generated_uri = 'public://styles/image_effects_test/public/' . \Drupal::service('file_system')->basename($original_uri);
// Test EXACT size canvas.
$effect = ['id' => 'image_effects_set_canvas', 'data' => ['canvas_size' => 'exact', 'canvas_color][container][transparent' => FALSE, 'canvas_color][container][hex' => '#FF00FF', 'canvas_color][container][opacity' => 100, 'exact][width' => '200%', 'exact][height' => '200%']];
$uuid = $this->addEffectToTestStyle($effect);
// Load Image Style.
$image_style = ImageStyle::load('image_effects_test');
// Check that ::transformDimensions returns expected dimensions.
$image = $image_factory->get($original_uri);
$this->assertEqual(40, $image->getWidth());
$this->assertEqual(20, $image->getHeight());
$url = file_url_transform_relative($image_style->buildUrl($original_uri));
$variables = array('#theme' => 'image_style', '#style_name' => 'image_effects_test', '#uri' => $original_uri, '#width' => $image->getWidth(), '#height' => $image->getHeight());
$this->assertEqual('<img src="' . $url . '" width="80" height="40" alt="" class="image-style-image-effects-test" />', $this->getImageTag($variables));
// Check that ::applyEffect generates image with expected canvas.
$image_style->createDerivative($original_uri, $image_style->buildUri($original_uri));
$image = $image_factory->get($generated_uri, 'gd');
$this->assertEqual(80, $image->getWidth());
$this->assertEqual(40, $image->getHeight());
$this->assertTrue($this->colorsAreEqual($this->fuchsia, $this->getPixelColor($image, 0, 0)));
$this->assertTrue($this->colorsAreEqual($this->fuchsia, $this->getPixelColor($image, 79, 0)));
$this->assertTrue($this->colorsAreEqual($this->fuchsia, $this->getPixelColor($image, 0, 39)));
$this->assertTrue($this->colorsAreEqual($this->fuchsia, $this->getPixelColor($image, 79, 39)));
// Remove effect.
$this->removeEffectFromTestStyle($uuid);
// Test RELATIVE size canvas.
$effect = ['id' => 'image_effects_set_canvas', 'data' => ['canvas_size' => 'relative', 'canvas_color][container][transparent' => FALSE, 'canvas_color][container][hex' => '#FFFF00', 'canvas_color][container][opacity' => 100, 'relative][right' => 10, 'relative][left' => 20, 'relative][top' => 30, 'relative][bottom' => 40]];
$uuid = $this->addEffectToTestStyle($effect);
// Load Image Style.
$image_style = ImageStyle::load('image_effects_test');
// Check that ::transformDimensions returns expected dimensions.
$image = $image_factory->get($original_uri);
$this->assertEqual(40, $image->getWidth());
$this->assertEqual(20, $image->getHeight());
$url = file_url_transform_relative($image_style->buildUrl($original_uri));
$variables = array('#theme' => 'image_style', '#style_name' => 'image_effects_test', '#uri' => $original_uri, '#width' => $image->getWidth(), '#height' => $image->getHeight());
$this->assertEqual('<img src="' . $url . '" width="70" height="90" alt="" class="image-style-image-effects-test" />', $this->getImageTag($variables));
// Check that ::applyEffect generates image with expected canvas.
$image_style->createDerivative($original_uri, $image_style->buildUri($original_uri));
$image = $image_factory->get($generated_uri, 'gd');
$this->assertEqual(70, $image->getWidth());
$this->assertEqual(90, $image->getHeight());
$this->assertTrue($this->colorsAreEqual($this->yellow, $this->getPixelColor($image, 0, 0)));
$this->assertTrue($this->colorsAreEqual($this->yellow, $this->getPixelColor($image, 69, 0)));
$this->assertTrue($this->colorsAreEqual($this->yellow, $this->getPixelColor($image, 0, 89)));
$this->assertTrue($this->colorsAreEqual($this->yellow, $this->getPixelColor($image, 69, 89)));
// Remove effect.
$this->removeEffectFromTestStyle($uuid);
}
示例13: testImport
/**
* Tests importing image styles.
*/
public function testImport()
{
$style = ImageStyle::create(['name' => 'test']);
$style->addImageEffect(['id' => 'image_module_test_null']);
$style->addImageEffect(['id' => 'image_module_test_null']);
$style->save();
$this->assertEqual(count($style->getEffects()), 2);
$uuid = \Drupal::service('uuid')->generate();
$style->set('effects', [$uuid => ['id' => 'image_module_test_null']]);
$style->save();
$style = ImageStyle::load('test');
$this->assertEqual(count($style->getEffects()), 1);
}
示例14: testPassingMigration
/**
* Test basic passing migrations.
*/
public function testPassingMigration()
{
$this->executeMigration('d6_imagecache_presets');
/** @var \Drupal\image\Entity\ImageStyle $style */
$style = ImageStyle::load('big_blue_cheese');
// Check basic Style info.
$this->assertIdentical('big_blue_cheese', $style->get('name'), 'ImageStyle name set correctly');
$this->assertIdentical('big_blue_cheese', $style->get('label'), 'ImageStyle label set correctly');
// Test effects.
$effects = $style->getEffects();
// Check crop effect.
$this->assertImageEffect($effects, 'image_crop', ['width' => 555, 'height' => 5555, 'anchor' => 'center-center']);
// Check resize effect.
$this->assertImageEffect($effects, 'image_resize', ['width' => 55, 'height' => 55]);
// Check rotate effect.
$this->assertImageEffect($effects, 'image_rotate', ['degrees' => 55, 'random' => FALSE, 'bgcolor' => '']);
}
示例15: testFlush
/**
* General test to flush a style.
*/
function testFlush()
{
// Setup a style to be created and effects to add to it.
$style_name = strtolower($this->randomMachineName(10));
$style_label = $this->randomString();
$style_path = 'admin/config/media/image-styles/manage/' . $style_name;
$effect_edits = array('image_resize' => array('data[width]' => 100, 'data[height]' => 101), 'image_scale' => array('data[width]' => 110, 'data[height]' => 111, 'data[upscale]' => 1));
// Add style form.
$edit = array('name' => $style_name, 'label' => $style_label);
$this->drupalPostForm('admin/config/media/image-styles/add', $edit, t('Create new style'));
// Add each sample effect to the style.
foreach ($effect_edits as $effect => $edit) {
// Add the effect.
$this->drupalPostForm($style_path, array('new' => $effect), t('Add'));
if (!empty($edit)) {
$this->drupalPostForm(NULL, $edit, t('Add effect'));
}
}
// Load the saved image style.
$style = ImageStyle::load($style_name);
// Create an image for the 'public' wrapper.
$image_path = $this->createSampleImage($style, 'public');
// Expecting to find 2 images, one is the sample.png image shown in
// image style preview.
$this->assertEqual($this->getImageCount($style, 'public'), 2, format_string('Image style %style image %file successfully generated.', array('%style' => $style->label(), '%file' => $image_path)));
// Create an image for the 'private' wrapper.
$image_path = $this->createSampleImage($style, 'private');
$this->assertEqual($this->getImageCount($style, 'private'), 1, format_string('Image style %style image %file successfully generated.', array('%style' => $style->label(), '%file' => $image_path)));
// Remove the 'image_scale' effect and updates the style, which in turn
// forces an image style flush.
$style_path = 'admin/config/media/image-styles/manage/' . $style->id();
$uuids = array();
foreach ($style->getEffects() as $uuid => $effect) {
$uuids[$effect->getPluginId()] = $uuid;
}
$this->drupalPostForm($style_path . '/effects/' . $uuids['image_scale'] . '/delete', array(), t('Delete'));
$this->assertResponse(200);
$this->drupalPostForm($style_path, array(), t('Update style'));
$this->assertResponse(200);
// Post flush, expected 1 image in the 'public' wrapper (sample.png).
$this->assertEqual($this->getImageCount($style, 'public'), 1, format_string('Image style %style flushed correctly for %wrapper wrapper.', array('%style' => $style->label(), '%wrapper' => 'public')));
// Post flush, expected no image in the 'private' wrapper.
$this->assertEqual($this->getImageCount($style, 'private'), 0, format_string('Image style %style flushed correctly for %wrapper wrapper.', array('%style' => $style->label(), '%wrapper' => 'private')));
}