getTransparentColor example

// 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)) {
      if (imagecopyresampled($this->getToolkit()->getResource()$original_resource, 0, 0, 0, 0, $width$height$width$height)) {
        imagedestroy($original_resource);
        return TRUE;
      }
      // In case of error, reset resource and type to as it was.       $this->getToolkit()->setResource($original_resource);
      $this->getToolkit()->setType($original_type);
    }
    
$this->assertSame(20, $image->getHeight());
    $this->assertSame(image_type_to_mime_type($type)$image->getMimeType());
    $this->assertTrue($image->save($file_path), "Image '$file' should have been saved successfully, but it has not.");

    // Reload and check saved image.     $image_reloaded = $this->imageFactory->get($file_path);
    $this->assertTrue($image_reloaded->isValid());
    $this->assertSame(50, $image_reloaded->getWidth());
    $this->assertSame(20, $image_reloaded->getHeight());
    $this->assertSame(image_type_to_mime_type($type)$image_reloaded->getMimeType());
    if ($image_reloaded->getToolkit()->getType() == IMAGETYPE_GIF) {
      $this->assertSame('#ffff00', $image_reloaded->getToolkit()->getTransparentColor(), "Image '$file' after reload should have color channel set to #ffff00, but it has not.");
    }
    else {
      $this->assertNull($image_reloaded->getToolkit()->getTransparentColor(), "Image '$file' after reload should have no color channel set, but it has.");
    }
  }

  /** * Tests failures of the 'create_new' operation. */
  public function testCreateNewFailures(): void {
    $image = $this->imageFactory->get();
    
if (imageistruecolor($resource)) {
      return TRUE;
    }
    else {
      // Convert indexed images to truecolor, copying the image to a new       // truecolor resource, so that filters work correctly and don't result       // in unnecessary dither.       $data = [
        'width' => imagesx($resource),
        'height' => imagesy($resource),
        'extension' => image_type_to_extension($this->getType(), FALSE),
        'transparent_color' => $this->getTransparentColor(),
        'is_temp' => TRUE,
      ];
      if ($this->apply('create_new', $data)) {
        imagecopy($this->getResource()$resource, 0, 0, 0, 0, imagesx($resource)imagesy($resource));
        imagedestroy($resource);
      }
    }
    return (bool) $this->getResource();
  }

  /** * {@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.         imagedestroy($this->getToolkit()->getResource());
        

  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.         imagedestroy($this->getToolkit()->getResource());
        
Home | Imprint | This part of the site doesn't use cookies.