Commit ff0818e6 authored by Matt Glaman's avatar Matt Glaman
Browse files

Issue #3274796 by Barrett: Small assets are up-sized to configured max image size

parent d6f17a0f
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -182,7 +182,7 @@ class AcquiadamConfig extends ConfigFormBase {
    $form['image']['size_limit'] = [
      '#type' => 'select',
      '#title' => $this->t('Image size limit'),
      '#description' => $this->t('Limit the source size used when importing image assets. The largest available size up to the selected will be used.'),
      '#description' => $this->t('Limit the source size used when importing image assets. Images larger than the selected size will be scaled down to this setting.'),
      '#options' => [
        100 => 100,
        150 => 150,
+19 −8
Original line number Diff line number Diff line
@@ -120,19 +120,30 @@ class AssetImageHelper implements ContainerInjectionInterface {
    if (empty($asset->embeds)) {
      return FALSE;
    }
    // Check if file_properties are loaded with asset.
    if (empty($asset->file_properties)) {
      $dimension = "w";

    $image_properties = $asset->file_properties->image_properties ?? NULL;
    if (!$image_properties) {
      $query = [];
    }
    else {
      if ($image_properties->aspect_ratio > 1) {
        $dimension = 'w';
        $size = $image_properties->width;
      }
      else {
      $dimension = ($asset->file_properties->image_properties->aspect_ratio > 1) ? "w" : "h";
        $dimension = 'h';
        $size = $image_properties->height;
      }

    $url = Url::fromUri($asset->embeds->original->url, [
      "query" => [
        $dimension => $thumbnailSize,
      $scaled_size = min($thumbnailSize, $size);
      $query = [
        $dimension => $scaled_size,
        "q" => $this->configFactory->get('media_acquiadam.settings')->get('image_quality') ?? 80,
      ],
      ];
    }

    $url = Url::fromUri($asset->embeds->original->url, [
      'query' => $query,
    ]);

    return str_replace("/original/", "/png/", $url->toString());
+4 −4
Original line number Diff line number Diff line
@@ -66,12 +66,12 @@ class AssetImageHelperTest extends UnitTestCase {

    // Ensure we get the  biggest if nothing was available.
    $tn_url = $this->assetImageHelper->getThumbnailUrlBySize($asset, 1280);
    $this->assertEquals('https://demo.widen.net/content/demoextid/png/theHumanRaceMakesSense.jpg?u=lv0nkk&download=true&h=1280&q=80',
    $this->assertEquals('https://demo.widen.net/content/demoextid/png/theHumanRaceMakesSense.jpg?u=lv0nkk&download=true&h=650&q=80',
      $tn_url);

    // Ensure we get the biggest when nothing is specified.
    $tn_url = $this->assetImageHelper->getThumbnailUrlBySize($asset);
    $this->assertEquals('https://demo.widen.net/content/demoextid/png/theHumanRaceMakesSense.jpg?u=lv0nkk&download=true&h=2048&q=80',
    $this->assertEquals('https://demo.widen.net/content/demoextid/png/theHumanRaceMakesSense.jpg?u=lv0nkk&download=true&h=650&q=80',
      $tn_url);
  }

@@ -235,8 +235,8 @@ class AssetImageHelperTest extends UnitTestCase {
        ['https://demo.widen.net/content/demoextid/original/theHumanRaceMakesSense.jpg?u=lv0nkk&download=true', ['query' => ['h' => 100, 'q' => 80], 'external' => TRUE], FALSE, 'https://demo.widen.net/content/demoextid/original/theHumanRaceMakesSense.jpg?u=lv0nkk&download=true&h=100&q=80'],
        ['https://demo.widen.net/content/demoextid/original/theHumanRaceMakesSense.jpg?u=lv0nkk&download=true', ['query' => ['h' => 120, 'q' => 80], 'external' => TRUE], FALSE, 'https://demo.widen.net/content/demoextid/original/theHumanRaceMakesSense.jpg?u=lv0nkk&download=true&h=120&q=80'],
        ['https://demo.widen.net/content/demoextid/original/theHumanRaceMakesSense.jpg?u=lv0nkk&download=true', ['query' => ['h' => 350, 'q' => 80], 'external' => TRUE], FALSE, 'https://demo.widen.net/content/demoextid/original/theHumanRaceMakesSense.jpg?u=lv0nkk&download=true&h=350&q=80'],
        ['https://demo.widen.net/content/demoextid/original/theHumanRaceMakesSense.jpg?u=lv0nkk&download=true', ['query' => ['h' => 1280, 'q' => 80], 'external' => TRUE], FALSE, 'https://demo.widen.net/content/demoextid/original/theHumanRaceMakesSense.jpg?u=lv0nkk&download=true&h=1280&q=80'],
        ['https://demo.widen.net/content/demoextid/original/theHumanRaceMakesSense.jpg?u=lv0nkk&download=true', ['query' => ['h' => 2048, 'q' => 80], 'external' => TRUE], FALSE, 'https://demo.widen.net/content/demoextid/original/theHumanRaceMakesSense.jpg?u=lv0nkk&download=true&h=2048&q=80'],
        ['https://demo.widen.net/content/demoextid/original/theHumanRaceMakesSense.jpg?u=lv0nkk&download=true', ['query' => ['h' => 650, 'q' => 80], 'external' => TRUE], FALSE, 'https://demo.widen.net/content/demoextid/original/theHumanRaceMakesSense.jpg?u=lv0nkk&download=true&h=650&q=80'],
        ['https://demo.widen.net/content/demoextid/original/theHumanRaceMakesSense.jpg?u=lv0nkk&download=true', ['query' => ['h' => 650, 'q' => 80], 'external' => TRUE], FALSE, 'https://demo.widen.net/content/demoextid/original/theHumanRaceMakesSense.jpg?u=lv0nkk&download=true&h=650&q=80'],
      ]);

    $entity_type_manager = $this->getMockBuilder(EntityTypeManagerInterface::class)