imagecreatetruecolor example

/** * @param resource $image * @param array{width: int, height: int} $originalSize * @param array{width: int, height: int} $newSize * * @return resource */
    private function createNewImage($image, array $originalSize, array $newSize, string $extension)
    {
        // Creates a new image with given size         $newImage = imagecreatetruecolor($newSize['width']$newSize['height']);
        if ($newImage === false) {
            throw new RuntimeException('Could not create image');
        }

        if (\in_array($extension['jpg', 'jpeg'])) {
            $background = (int) imagecolorallocate($newImage, 255, 255, 255);
            imagefill($newImage, 0, 0, $background);
        } else {
            // Disables blending             imagealphablending($newImage, false);
        }
        
/** * {@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) {
      case IMAGETYPE_PNG:
      case IMAGETYPE_WEBP:
        imagealphablending($res, FALSE);
        $transparency = imagecolorallocatealpha($res, 0, 0, 0, 127);
        imagefill($res, 0, 0, $transparency);
        imagealphablending($res, TRUE);
        

function wp_imagecreatetruecolor( $width$height ) {
    $img = imagecreatetruecolor( $width$height );

    if ( is_gd_image( $img )
        && function_exists( 'imagealphablending' ) && function_exists( 'imagesavealpha' )
    ) {
        imagealphablending( $img, false );
        imagesavealpha( $img, true );
    }

    return $img;
}

'width' => $calculatedWidth,
            'height' => $calculatedHeight,
        ];
    }

    /** * @param array{width: int, height: int} $originalImageSize * @param array{width: int, height: int} $thumbnailSize */
    private function createNewImage(\GdImage $mediaImage, MediaType $type, array $originalImageSize, array $thumbnailSize): \GdImage
    {
        $thumbnail = imagecreatetruecolor($thumbnailSize['width']$thumbnailSize['height']);

        if ($thumbnail === false) {
            throw MediaException::cannotCreateImage();
        }

        if (!$type->is(ImageType::TRANSPARENT)) {
            $colorWhite = (int) imagecolorallocate($thumbnail, 255, 255, 255);
            imagefill($thumbnail, 0, 0, $colorWhite);
        } else {
            imagealphablending($thumbnail, false);
        }

        
if (empty($captcha)) {
            $captcha = $this->getCaptchaFile(self::PATH_CAPTCHA_IMAGE_FALLBACK);
        }

        if (empty($font)) {
            $font = $this->getCaptchaFile(self::PATH_CAPTCHA_FONT_FALLBACK);
        }

        if (!empty($captcha)) {
            $im = imagecreatefromjpeg($captcha);
        } else {
            $im = imagecreatetruecolor(162, 87);
        }

        if ($im === false) {
            throw new RuntimeException('Could not create captcha image');
        }

        if (!empty($this->config->get('CaptchaColor'))) {
            $colors = explode(',', $this->config->get('CaptchaColor'));
        } else {
            $colors = explode(',', '255,0,0');
        }

        
Home | Imprint | This part of the site doesn't use cookies.