extensionToImageType example

    // types.     $expected_image_types = [
      'png' => IMAGETYPE_PNG,
      'gif' => IMAGETYPE_GIF,
      'jpeg' => IMAGETYPE_JPEG,
      'jpg' => IMAGETYPE_JPEG,
      'jpe' => IMAGETYPE_JPEG,
      'webp' => IMAGETYPE_WEBP,
    ];
    $image = $this->imageFactory->get();
    foreach ($expected_image_types as $extension => $expected_image_type) {
      $this->assertSame($expected_image_type$image->getToolkit()->extensionToImageType($extension));
    }
  }

  /** * Data provider for ::testCreateImageFromScratch(). */
  public function providerSupportedImageTypes(): array {
    return [
      [IMAGETYPE_PNG],
      [IMAGETYPE_GIF],
      [IMAGETYPE_JPEG],
      [
throw new \InvalidArgumentException("Invalid transparent color ({$arguments['transparent_color']}) specified for the image 'create_new' operation");
    }

    return $arguments;
  }

  /** * {@inheritdoc} */
  protected function execute(array $arguments) {
    // Get the image type.     $type = $this->getToolkit()->extensionToImageType($arguments['extension']);

    // Store the original GD resource.     $original_res = $this->getToolkit()->getResource();

    // Create the resource.     if (!$res = imagecreatetruecolor($arguments['width']$arguments['height'])) {
      return FALSE;
    }

    // Fill the resource with transparency as possible.     switch ($type) {
      
Home | Imprint | This part of the site doesn't use cookies.