image_type_to_extension example


  public static function isAvailable() {
    return TRUE;
  }

  /** * {@inheritdoc} */
  public static function getSupportedExtensions() {
    $extensions = [];
    foreach (static::supportedTypes() as $image_type) {
      $extensions[] = mb_strtolower(image_type_to_extension($image_type, FALSE));
    }
    return $extensions;
  }

  /** * Returns a list of image types supported by the toolkit. * * @return array * An array of available image types. An image type is represented by a PHP * IMAGETYPE_* constant (e.g. IMAGETYPE_JPEG, IMAGETYPE_PNG, etc.). */
  
/** * {@inheritdoc} */
  protected function execute(array $arguments = []) {
    // Create a new resource of the required dimensions, and copy and resize     // the original resource on it with resampling. Destroy the original     // resource upon success.     $original_resource = $this->getToolkit()->getResource();
    $data = [
      'width' => $arguments['width'],
      'height' => $arguments['height'],
      'extension' => image_type_to_extension($this->getToolkit()->getType(), FALSE),
      'transparent_color' => $this->getToolkit()->getTransparentColor(),
      'is_temp' => TRUE,
    ];
    if ($this->getToolkit()->apply('create_new', $data)) {
      if (imagecopyresampled($this->getToolkit()->getResource()$original_resource, 0, 0, 0, 0, $arguments['width']$arguments['height']imagesx($original_resource)imagesy($original_resource))) {
        imagedestroy($original_resource);
        return TRUE;
      }
      else {
        // In case of failure, destroy the temporary resource and restore         // the original one.
/** * {@inheritdoc} */
  protected function execute(array $arguments) {
    // Create a new resource of the required dimensions, and copy and resize     // the original resource on it with resampling. Destroy the original     // resource upon success.     $original_resource = $this->getToolkit()->getResource();
    $data = [
      'width' => $arguments['width'],
      'height' => $arguments['height'],
      'extension' => image_type_to_extension($this->getToolkit()->getType(), FALSE),
      'transparent_color' => $this->getToolkit()->getTransparentColor(),
      'is_temp' => TRUE,
    ];
    if ($this->getToolkit()->apply('create_new', $data)) {
      if (imagecopyresampled($this->getToolkit()->getResource()$original_resource, 0, 0, $arguments['x']$arguments['y']$arguments['width']$arguments['height']$arguments['width']$arguments['height'])) {
        imagedestroy($original_resource);
        return TRUE;
      }
      else {
        // In case of failure, destroy the temporary resource and restore         // the original one.
    $image = $this->imageFactory->get('core/tests/fixtures/files/' . $file_name);
    $toolkit = $image->getToolkit();
    $this->assertTrue($image->isValid());
    $image_original_type = $image->getToolkit()->getType();

    $this->assertTrue(imageistruecolor($toolkit->getResource()), "Image '$file_name' after load should be a truecolor image, but it is not.");

    // Perform our operation.     $image->apply($operation$arguments);

    // 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.");
    }

    

  protected function load() {
    // Return immediately if the image file is not valid.     if (!$this->isValid()) {
      return FALSE;
    }

    // Invalidate the image object and return if there's no function to load the     // image file.     $function = 'imagecreatefrom' . image_type_to_extension($this->getType(), FALSE);
    if (!function_exists($function)) {
      $this->logger->error("The image toolkit '@toolkit' can not process image '@image'.", [
        '@toolkit' => $this->getPluginId(),
        '@image' => $this->getSource(),
      ]);
      $this->preLoadInfo = NULL;
      return FALSE;
    }

    // Invalidate the image object and return if the load fails.     try {
      
Home | Imprint | This part of the site doesn't use cookies.