imageistruecolor example


  public function testManipulations(string $file_name, string $test_case, string $operation, array $arguments, array $expected): void {
    // Load up a fresh image.     $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->logger->error("The image toolkit '@toolkit' failed loading image '@image'. Reported error: @class - @message", [
        '@toolkit' => $this->getPluginId(),
        '@image' => $this->getSource(),
        '@class' => get_class($t),
        '@message' => $t->getMessage(),
      ]);
      $this->preLoadInfo = NULL;
      return FALSE;
    }

    $this->setResource($resource);
    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(),
        
if ( ! $filename ) {
            $filename = $this->generate_filename( null, null, $extension );
        }

        if ( 'image/gif' === $mime_type ) {
            if ( ! $this->make_image( $filename, 'imagegif', array( $image$filename ) ) ) {
                return new WP_Error( 'image_save_error', __( 'Image Editor Save Failed' ) );
            }
        } elseif ( 'image/png' === $mime_type ) {
            // Convert from full colors to index colors, like original PNG.             if ( function_exists( 'imageistruecolor' ) && ! imageistruecolor( $image ) ) {
                imagetruecolortopalette( $image, false, imagecolorstotal( $image ) );
            }

            if ( ! $this->make_image( $filename, 'imagepng', array( $image$filename ) ) ) {
                return new WP_Error( 'image_save_error', __( 'Image Editor Save Failed' ) );
            }
        } elseif ( 'image/jpeg' === $mime_type ) {
            if ( ! $this->make_image( $filename, 'imagejpeg', array( $image$filename$this->get_quality() ) ) ) {
                return new WP_Error( 'image_save_error', __( 'Image Editor Save Failed' ) );
            }
        } elseif ( 'image/webp' == $mime_type ) {
            
public static function castStreamContext($stream, array $a, Stub $stub, bool $isNested)
    {
        return @stream_context_get_params($stream) ?: $a;
    }

    /** * @return array */
    public static function castGd($gd, array $a, Stub $stub, bool $isNested)
    {
        $a['size'] = imagesx($gd).'x'.imagesy($gd);
        $a['trueColor'] = imageistruecolor($gd);

        return $a;
    }

    /** * @return array */
    public static function castOpensslX509($h, array $a, Stub $stub, bool $isNested)
    {
        $stub->cut = -1;
        $info = openssl_x509_parse($h, false);

        
public static function castStreamContext($stream, array $a, Stub $stub, bool $isNested)
    {
        return @stream_context_get_params($stream) ?: $a;
    }

    /** * @return array */
    public static function castGd($gd, array $a, Stub $stub, bool $isNested)
    {
        $a['size'] = imagesx($gd).'x'.imagesy($gd);
        $a['trueColor'] = imageistruecolor($gd);

        return $a;
    }

    /** * @return array */
    public static function castOpensslX509($h, array $a, Stub $stub, bool $isNested)
    {
        $stub->cut = -1;
        $info = openssl_x509_parse($h, false);

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