Imagick::getImageType

(PECL imagick 2, PECL imagick 3)

Imagick::getImageType β€” Π’ΠΎΠ·Π²Ρ€Π°Ρ‰Π°Π΅Ρ‚ Π²ΠΎΠ·ΠΌΠΎΠΆΠ½Ρ‹ΠΉ Ρ‚ΠΈΠΏ изобраТСния

ОписаниС

public function Imagick::getImageType(): int

ΠŸΠΎΠ»ΡƒΡ‡Π΅Π½ΠΈΠ΅ Π²ΠΎΠ·ΠΌΠΎΠΆΠ½ΠΎΠ³ΠΎ Ρ‚ΠΈΠΏΠ° изобраТСния.

Бписок ΠΏΠ°Ρ€Π°ΠΌΠ΅Ρ‚Ρ€ΠΎΠ²

Π‘ΠΈΠ³Π½Π°Ρ‚ΡƒΡ€Π° Ρ„ΡƒΠ½ΠΊΡ†ΠΈΠΈ Π½Π΅ содСрТит ΠΏΠ°Ρ€Π°ΠΌΠ΅Ρ‚Ρ€ΠΎΠ².

Π’ΠΎΠ·Π²Ρ€Π°Ρ‰Π°Π΅ΠΌΡ‹Π΅ значСния

Π’ΠΎΠ·Π²Ρ€Π°Ρ‰Π°Π΅Ρ‚ Π²ΠΎΠ·ΠΌΠΎΠΆΠ½Ρ‹ΠΉ Ρ‚ΠΈΠΏ изобраТСния.

Ошибки

Ѐункция выбрасываСт ΠΈΡΠΊΠ»ΡŽΡ‡Π΅Π½ΠΈΠ΅ ImagickException, Ссли Π²ΠΎΠ·Π½ΠΈΠΊΠ»Π° ошибка.

οΌ‹Π”ΠΎΠ±Π°Π²ΠΈΡ‚ΡŒ

ΠŸΡ€ΠΈΠΌΠ΅Ρ‡Π°Π½ΠΈΡ ΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚Π΅Π»Π΅ΠΉ 2 notes

up
0
holdoffhunger at gmail dot com ΒΆ
14 years ago
This function will return an integer, with that value being equal to the evaluated value of the IMGType Constants as defined by the ImageMagick class.  When accessing them, they look like "imagick::IMGTYPE_PALETTE", but with "_VALUE" values of: undefined, bilevel, grayscale, grayscalematte, palette, palettematte, truecolor, truecolormatte, colorseparation, colorseparationmatte, and optimize.  If you were to print out these values, you would have '0' for undefined, '1' for bilevel, '2' for grayscale, and so on.

For a BMP picture drawn in paint, I got back the value # 4 - Palette.  For a BMP or JPEG photograph of the ocean or jungle, I got back the value # 6 - Truecolor.  For an animated GIF file, I got back the value # 5 - Palette Matte.  For a black-and-white JPEG drawing, I got back the value # 2 - Grayscale.  These are the most common results I have gotten back with this function.

Some sample code :

<?php

            // Author: holdoffhunger@gmail.com
    
        // Imagick Type
        // ---------------------------------------------

    $imagick_type = new Imagick();
    
        // Open File
        // ---------------------------------------------
        
    $file_to_grab = "image_workshop_directory/test.bmp";
    
    $file_handle_for_viewing_image_file = fopen($file_to_grab, 'a+');
    
        // Grab File
        // ---------------------------------------------

    $imagick_type->readImageFile($file_handle_for_viewing_image_file);
    
        // Get Image Type Value
        // ---------------------------------------------
        
    $image_type = $imagick_type->getImageType();
    
        // Interpret Image Type Value
        // ---------------------------------------------

    switch($image_type)
    {
        case imagick::IMGTYPE_UNDEFINED:
            $image_type_title = "Undefined";
            break;
            
        case imagick::IMGTYPE_BILEVEL:
            $image_type_title = "Bilevel";
            break;
            
        case imagick::IMGTYPE_GRAYSCALE:
            $image_type_title = "Grayscale";
            break;
            
        case imagick::IMGTYPE_GRAYSCALEMATTE:
            $image_type_title = "Grayscale Matte";
            break;
            
        case imagick::IMGTYPE_PALETTE:
            $image_type_title = "Palette";
            break;
            
        case imagick::IMGTYPE_PALETTEMATTE:
            $image_type_title = "Palette Matte";
            break;
            
        case imagick::IMGTYPE_TRUECOLOR:
            $image_type_title = "Truecolor";
            break;
            
        case imagick::IMGTYPE_TRUECOLORMATTE:
            $image_type_title = "Truecolor Matte";
            break;
            
        case imagick::IMGTYPE_COLORSEPARATION:
            $image_type_title = "Color Separation";
            break;
            
        case imagick::IMGTYPE_COLORSEPARATIONMATTE:
            $image_type_title = "Color Separation Matte";
            break;
            
        case imagick::IMGTYPE_OPTIMIZE:
            $image_type_title = "Optimize";
            break;
    }
    
        // Print Image Type Value
        // ---------------------------------------------
        
    print("# $image_type - $image_type_title");

?>
up
-2
lukeydeluxe at gmail dot com ΒΆ
17 years ago
Remember, the result, if successful, is an Array, wich means you should call for example "$var[format]" if you want to know what format the file uses.