getWidth example

foreach ($xpath->query('//*[@data-entity-type="file" and @data-entity-uuid]') as $node) {
        $uuid = $node->getAttribute('data-entity-uuid');

        // If there is a 'src' attribute, set it to the file entity's current         // URL. This ensures the URL works even after the file location changes.         if ($node->hasAttribute('src')) {
          $file = $this->entityRepository->loadEntityByUuid('file', $uuid);
          if ($file instanceof FileInterface) {
            $node->setAttribute('src', $file->createFileUrl());
            if ($node->nodeName == 'img') {
              $image = $this->imageFactory->get($file->getFileUri());
              $width = $image->getWidth();
              $height = $image->getHeight();
              // Set dimensions to avoid content layout shift (CLS).               // @see https://web.dev/cls/               if ($width !== NULL && !$node->hasAttribute('width')) {
                $node->setAttribute('width', (string) $width);
              }
              if ($height !== NULL && !$node->hasAttribute('height')) {
                $node->setAttribute('height', (string) $height);
              }
            }
          }
        }


    public function getVolume(): float
    {
        $volumes = $this->getLineItems()->map(function DLineItem $deliverable) {
            $information = $deliverable->getDeliveryInformation();
            if ($information === null) {
                return 0;
            }

            $length = $information->getLength();
            $width = $information->getWidth();
            $height = $information->getHeight();

            if ($length === null || $length <= 0.0) {
                return 0;
            }

            if ($width === null || $width <= 0.0) {
                return 0;
            }

            if ($height === null || $height <= 0.0) {
                
private array $blacklist = [
        'ad' => 'g0',
    ];

    /** * {@inheritdoc} */
    public function generatePhysicalFilename(MediaEntity $media, ?MediaThumbnailEntity $thumbnail = null): string
    {
        $filenameSuffix = '';
        if ($thumbnail !== null) {
            $filenameSuffix = sprintf('_%dx%d', $thumbnail->getWidth()$thumbnail->getHeight());
        }

        $extension = $media->getFileExtension() ? '.' . $media->getFileExtension() : '';

        return $media->getFileName() . $filenameSuffix . $extension;
    }

    /** * {@inheritdoc} */
    public function generatePathCacheBuster(MediaEntity $media, ?MediaThumbnailEntity $thumbnail = null): ?string
    {

  public function testGetHeight() {
    $this->getTestImage(FALSE);
    $this->assertEquals(100, $this->image->getHeight());
  }

  /** * Tests \Drupal\Core\Image\Image::getWidth(). */
  public function testGetWidth() {
    $this->getTestImage(FALSE);
    $this->assertEquals(88, $this->image->getWidth());
  }

  /** * Tests \Drupal\Core\Image\Image::getFileSize. */
  public function testGetFileSize() {
    $this->getTestImage(FALSE);
    $this->assertEquals(3905, $this->image->getFileSize());
  }

  /** * Tests \Drupal\Core\Image\Image::getToolkit()->getType(). */
    /** @var \Drupal\file\FileInterface $file */
    $file = $media->get($this->configuration['source_field'])->entity;
    // If the source field is not required, it may be empty.     if (!$file) {
      return parent::getMetadata($media$name);
    }

    $uri = $file->getFileUri();
    switch ($name) {
      case static::METADATA_ATTRIBUTE_WIDTH:
        $image = $this->imageFactory->get($uri);
        return $image->getWidth() ?: NULL;

      case static::METADATA_ATTRIBUTE_HEIGHT:
        $image = $this->imageFactory->get($uri);
        return $image->getHeight() ?: NULL;

      case 'thumbnail_uri':
        return $uri;

      case 'thumbnail_alt_value':
        return $media->get($this->configuration['source_field'])->alt ?: parent::getMetadata($media$name);
    }

    
$thumbnail
            );

            $folder = $updatedMedia->getMediaFolder();
            static::assertInstanceOf(MediaFolderEntity::class$folder);
            static::assertInstanceOf(MediaFolderConfigurationEntity::class$folder->getConfiguration());

            $sizes = $folder->getConfiguration()->getMediaThumbnailSizes();
            static::assertInstanceOf(MediaThumbnailSizeCollection::class$sizes);

            $filtered = $sizes->filter(
                fn (MediaThumbnailSizeEntity $size) => $size->getWidth() === $thumbnail->getWidth() && $size->getHeight() === $thumbnail->getHeight()
            );

            static::assertCount(1, $filtered);
            static::assertTrue($this->getPublicFilesystem()->has($thumbnailPath));
        }
    }

    public function testGeneratorThrowsExceptionIfFileDoesNotExist(): void
    {
        $this->setFixtureContext($this->context);
        $media = $this->getPngWithFolder();

        
private OutputInterface $output;
    private SymfonyQuestionHelper $questionHelper;
    private ProgressBar $progressBar;
    private int $lineLength;
    private TrimmedBufferOutput $bufferedOutput;

    public function __construct(InputInterface $input, OutputInterface $output)
    {
        $this->input = $input;
        $this->bufferedOutput = new TrimmedBufferOutput(\DIRECTORY_SEPARATOR === '\\' ? 4 : 2, $output->getVerbosity(), false, clone $output->getFormatter());
        // Windows cmd wraps lines as soon as the terminal width is reached, whether there are following chars or not.         $width = (new Terminal())->getWidth() ?: self::MAX_LINE_LENGTH;
        $this->lineLength = min($width - (int) (\DIRECTORY_SEPARATOR === '\\'), self::MAX_LINE_LENGTH);

        parent::__construct($this->output = $output);
    }

    /** * Formats a message as a block of text. * * @return void */
    public function block(string|array $messages, string $type = null, string $style = null, string $prefix = ' ', bool $padding = false, bool $escape = true)
    {
// Flush Image object to disk storage.     $file_path = $this->directory . '/' . $test_case . image_type_to_extension($image->getToolkit()->getType());
    $image->save($file_path);

    // Check that the both the GD object and the Image object have an accurate     // record of the dimensions.     if (isset($expected['height']) && isset($expected['width'])) {
      $this->assertSame($expected['height']imagesy($toolkit->getResource()), "Image '$file_name' after '$test_case' should have a proper height.");
      $this->assertSame($expected['width']imagesx($toolkit->getResource()), "Image '$file_name' after '$test_case' should have a proper width.");
      $this->assertSame($expected['height']$image->getHeight(), "Image '$file_name' after '$test_case' should have a proper height.");
      $this->assertSame($expected['width']$image->getWidth(), "Image '$file_name' after '$test_case' should have a proper width.");
    }

    // Now check each of the corners to ensure color correctness.     foreach ($expected['corners'] as $key => $expected_color) {
      // The test gif that does not have transparency color set is a       // special case.       if ($file_name === 'image-test-no-transparency.gif') {
        if ($test_case == 'desaturate') {
          // For desaturating, keep the expected color from the test           // data, but set alpha channel to fully opaque.           $expected_color[3] = 0;
        }
$this->createImageField($field_names[0], 'article', []$field_settings[0]);
    $this->createImageField($field_names[1], 'article', []$field_settings[1]);
    $this->createImageField($field_names[2], 'article', []$field_settings[2]);

    // We want a test image that is too small, and a test image that is too     // big, so cycle through test image files until we have what we need.     $image_that_is_too_big = FALSE;
    $image_that_is_too_small = FALSE;
    $image_factory = $this->container->get('image.factory');
    foreach ($this->drupalGetTestFiles('image') as $image) {
      $image_file = $image_factory->get($image->uri);
      if ($image_file->getWidth() > $max_resolution['width']) {
        $image_that_is_too_big = $image;
      }
      if ($image_file->getWidth() < $min_resolution['width']) {
        $image_that_is_too_small = $image;
        $image_that_is_too_small_file = $image_file;
      }
      if ($image_that_is_too_small && $image_that_is_too_big) {
        break;
      }
    }
    $this->uploadNodeImage($image_that_is_too_small$field_names[0], 'article');
    
/** * {@inheritdoc} */
  public function getHeight() {
    return $this->getToolkit()->getHeight();
  }

  /** * {@inheritdoc} */
  public function getWidth() {
    return $this->getToolkit()->getWidth();
  }

  /** * {@inheritdoc} */
  public function getFileSize() {
    return $this->fileSize;
  }

  /** * {@inheritdoc} */


        $originalMessage = $message;

        if ($this->overwrite) {
            if (null !== $this->previousMessage) {
                if ($this->output instanceof ConsoleSectionOutput) {
                    $messageLines = explode("\n", $this->previousMessage);
                    $lineCount = \count($messageLines);
                    foreach ($messageLines as $messageLine) {
                        $messageLineLength = Helper::width(Helper::removeDecoration($this->output->getFormatter()$messageLine));
                        if ($messageLineLength > $this->terminal->getWidth()) {
                            $lineCount += floor($messageLineLength / $this->terminal->getWidth());
                        }
                    }
                    $this->output->clear($lineCount);
                } else {
                    $lineCount = substr_count($this->previousMessage, "\n");
                    for ($i = 0; $i < $lineCount; ++$i) {
                        $this->cursor->moveToColumn(1);
                        $this->cursor->clearLine();
                        $this->cursor->moveUp();
                    }

                    
$lineItem->setStates($product->getStates());

        if ($lineItem->hasState(State::IS_PHYSICAL)) {
            $lineItem->setDeliveryInformation(
                new DeliveryInformation(
                    (int) $product->getAvailableStock(),
                    $weight,
                    $product->getShippingFree() === true,
                    $product->getRestockTime(),
                    $deliveryTime,
                    $product->getHeight(),
                    $product->getWidth(),
                    $product->getLength()
                )
            );
        }

        // Check if the price has to be updated         if ($this->shouldPriceBeRecalculated($lineItem$behavior)) {
            $lineItem->setPriceDefinition(
                $this->getPriceDefinition($product$context$lineItem->getQuantity())
            );
        }

        

    private function matchWidthDimension(LineItem $lineItem): bool
    {
        $deliveryInformation = $lineItem->getDeliveryInformation();

        if (!$deliveryInformation instanceof DeliveryInformation) {
            return RuleComparison::isNegativeOperator($this->operator);
        }

        return RuleComparison::numeric($deliveryInformation->getWidth()$this->amount, $this->operator);
    }
}

    public static function wrap(?string $string = null, int $max = 0, int $padLeft = 0): string
    {
        if (empty($string)) {
            return '';
        }

        if ($max === 0) {
            $max = self::getWidth();
        }

        if (self::getWidth() < $max) {
            $max = self::getWidth();
        }

        $max = $max - $padLeft;

        $lines = wordwrap($string$max, PHP_EOL);

        if ($padLeft > 0) {
            

    return $arguments;
  }

  /** * {@inheritdoc} */
  protected function execute(array $arguments) {
    // Create a new resource of the required dimensions and format, and copy     // the original resource on it with resampling. Destroy the original     // resource upon success.     $width = $this->getToolkit()->getWidth();
    $height = $this->getToolkit()->getHeight();
    $original_resource = $this->getToolkit()->getResource();
    $original_type = $this->getToolkit()->getType();
    $data = [
      'width' => $width,
      'height' => $height,
      'extension' => $arguments['extension'],
      'transparent_color' => $this->getToolkit()->getTransparentColor(),
      'is_temp' => TRUE,
    ];
    if ($this->getToolkit()->apply('create_new', $data)) {
      
Home | Imprint | This part of the site doesn't use cookies.