PHP.mk документација

Imagick::identifyImage

Почист и полокален преглед на PHP референцата, со задржана структура од PHP.net и подобра читливост за примери, секции и белешки.

imagick.identifyimage.php PHP.net прокси Преводот се освежува
Оригинал на PHP.net
Патека imagick.identifyimage.php Локална патека за оваа страница.
Извор php.net/manual/en Оригиналниот HTML се реупотребува и локално се стилизира.
Режим Прокси + превод во позадина Кодовите, табелите и белешките остануваат читливи во истиот тек.
Imagick::identifyImage

Референца за `imagick.identifyimage.php` со подобрена типографија и навигација.

imagick.identifyimage.php

Imagick::identifyImage

(PECL imagick 2, PECL imagick 3)

Imagick::identifyImageIdentifies an image and fetches attributes

= NULL

public Imagick::identifyImage(bool $appendRawOutput = false): array

Identifies an image and returns the attributes. Attributes include the image width, height, size, and others.

Параметри

appendRawOutput

Враќа true then the raw output is appended to the array.

Вратени вредности

Identifies an image and returns the attributes. Attributes include the image width, height, size, and others.

Errors/Exceptions

Фрла ImagickException при грешка.

Примери

Example #1 Example Result Format

Array
(
    [imageName] => /some/path/image.jpg
    [format] => JPEG (Joint Photographic Experts Group JFIF format)
    [geometry] => Array
        (
            [width] => 90
            [height] => 90
        )

    [type] => TrueColor
    [colorSpace] => RGB
    [resolution] => Array
        (
            [x] => 300
            [y] => 300
        )

    [units] => PixelsPerInch
    [fileSize] => 1.88672kb
    [compression] => JPEG
    [signature] => 9a6dc8f604f97d0d691c0286176ddf992e188f0bebba98494b2146ee2d7118da
)

Белешки од корисници 3 белешки

rhuanpachecok at gmail dot com
пред 5 години
I have created a function to parse the "rawOutput" because the information provided by this function is quite useless.

function parseIdentify($info) {
    $lines = explode("\n", $info);
    
    $outputs = [];
    $output = [];
    $keys = [];
    
    $currSpaces = 0;
    $raw = false;
    
    foreach($lines as $line) {
        $trimLine = trim($line);
        
        if(empty($trimLine)) continue;
        
        if($raw) {
            preg_match('/^[0-9]+:\s/', $trimLine, $match);
            
            if(!empty($match)) {
                $regex = '/([\d]+):';
                $regex .= '\s(\([\d|\s]{1,3},[\d|\s]{1,3},[\d|\s]{1,3},[\d|\s]{1,3}\))';
                $regex .= '\s(#\w+)';
                $regex .= '\s(srgba\([\d|\s]{1,3},[\d|\s]{1,3},[\d|\s]{1,3},[\d|\s|.]+\)|\w+)/';

                preg_match($regex, $trimLine, $matches);
                array_shift($matches);
                
                $output['Image'][$raw][] = $matches;
                
                continue;
            }
            
            else {
                $raw = false;
                array_pop($keys);
            }
        }
        
        preg_match('/^\s+/', $line, $match);
        
        $spaces = isset($match[0]) ? strlen($match[0]) : $spaces = 0;
        $parts = preg_split('/:\s/', $trimLine, 2);
        
        $_key = ucwords($parts[0]);
        $_key = str_replace(' ', '', $_key);
        $_val = isset($parts[1]) ? $parts[1] : [];
        
        if($_key == 'Image') {
            if(!empty($output)) {
                $outputs[] = $output['Image'];
                $output = [];
            }
            
            $_val = [];
        }
        
        if($spaces < $currSpaces) {
            for($i = 0; $i < ($currSpaces - $spaces) / 2; $i++) {
                array_pop($keys);
            }
        }
        
        if(is_array($_val)) {
            $_key = rtrim($_key, ':');
            $keys[] = $_key;
            
            if($_key == 'Histogram' || $_key == 'Colormap') {
                $raw = $_key;
            }
        }
        
        $currSpaces = $spaces;
        $arr = &$output;
        
        foreach($keys as $key) {
            if(!isset($arr[$key])) {
                $arr[$key] = $_val;
            }
            
            $arr = &$arr[$key];
        }
        
        if(!is_array($_val)) {
            $arr[$_key] = $_val;
        }
        
    }
    
    $outputs[] = $output['Image'];
    
    return count($outputs) > 1 ? $outputs : $outputs[0];
}

Usage example:

$img = new Imagick('example.png');
$identify = parseIdentify($img->identifyImage(true)['rawOutput']);

But the "rawOutput" that this function returns only contains the first frame if it is a GIF. Alternatively you can use the command "identify" to get the data of all the frames:

$identify = parseIdentify(shell_exec('identify -verbose example.gif'));
php at ontheroad dot net dot nz
пред 15 години
If you use the option to append the raw output, you can extract the mime type from there.  I'm not sure what's going on in the background here, but it seems far less useful than the command line identify tool.
rob at OhReally dot nl
пред 17 години
The array returned by Imagick::identifyImage():

Array
(
    [imageName] => /some/path/image.jpg
    [format] => JPEG (Joint Photographic Experts Group JFIF format)
    [geometry] => Array
        (
            [width] => 90
            [height] => 90
        )

    [type] => TrueColor
    [colorSpace] => RGB
    [resolution] => Array
        (
            [x] => 300
            [y] => 300
        )

    [units] => PixelsPerInch
    [fileSize] => 1.88672kb
    [compression] => JPEG
    [signature] => 9a6dc8f604f97d0d691c0286176ddf992e188f0bebba98494b2146ee2d7118da
)

Looks like the only way to get the mimetype is getimagesize()...
Навигација

Прелистувај сродни теми и функции.

На оваа страница

Автоматски outline од активната документација.

Насловите ќе се појават тука по вчитување.

Попрегледно читање

Примерите, changelog табелите и user notes се визуелно издвоени за да не се губат во долгата содржина.

Брз совет Користи го outline-от Скокни директно на главните секции од активната страница.
Извор Оригиналниот линк останува достапен Кога ти треба целосен upstream context, отвори го PHP.net во нов tab.