8

私はこの問題に一日中苦労しており、ドキュメントが見つからないことに驚いています!

Web サイトに画像をアップロードしています。各画像の ICC プロファイルの名前を抽出し、画像の説明で使用したいと考えています。これまでのところ、標準の PHP では結果が生成されません。Photoshop、Bridge、Exiftool で画像を確認しましたが、それぞれにプロファイルが埋め込まれていることがわかりました。

<?php 
$info = exif_read_data($image);
echo 'ICC Profile: '.$info['ICC_Profile'].'<br>';
echo 'ICC Profile: '.$info['CurrentICCProfile'].'<br>';
echo 'ICC Profile: '.$info['ColorSpace'].'<br>';
?>

Imagick は、以下を使用して最高の結果を生み出しました。

$imagick = new Imagick();
$imagick->readImage($image);
print_r ($imagick->getImageProfiles("icc",true));

プロファイルを実際に言及しているが、使用可能な文字列ではない配列を生成しています。どんな助けでも感謝します。

私はこれらのバージョンを使用しています:

PHP バージョン 5.2.17 - imagick モジュール バージョン 3.0.1 - ImageMagick バージョン 6.7.6-8

そしてprint_r戻ります ('ProPhoto RGB' ICC プロファイルの場合):

Array ( [icc] => �KCMSmntrRGB XYZ � :acspMSFTKODAROMM���+KODAcprtHdesc\�wtpt�rTRC�gTRC�bTRC�rXYZgXYZbXYZ,dmnd@ndmdd�mmod�(textCopyright (c) Eastman Kodak Company, 1999, all rights reserved.desc ProPhoto RGB��ProPhoto RGB ProPhoto RGBXYZ ���,curv�XYZ �4I�XYZ "��>XYZ �-descKODAK��KODAKKODAKdesc'Reference Output Medium Metric(ROMM) (��Reference Output Medium Metric(ROMM) ) 'Reference Output Medium Metric(ROMM) mmod���;� )

完全に(Exiftoolから):

Profile CMM Type                : KCMS
Profile Version                 : 2.1.0
Profile Class                   : Display Device Profile
Color Space Data                : RGB
Profile Connection Space        : XYZ
Profile Date Time               : 1998:12:01 18:58:21
Profile File Signature          : acsp
Primary Platform                : Microsoft Corporation
CMM Flags                       : Not Embedded, Independent
Device Manufacturer             : KODA
Device Model                    : ROMM
Device Attributes               : Reflective, Glossy, Positive, Color
Rendering Intent                : Perceptual
Connection Space Illuminant     : 0.9642 1 0.82487
Profile Creator                 : KODA
Profile ID                      : 0
Profile Copyright               : Copyright (c) Eastman Kodak Company, 1999, all rights reserved.
Profile Description             : ProPhoto RGB
Media White Point               : 0.9642 1 0.82489
Red Tone Reproduction Curve     : (Binary data 14 bytes, use -b option to extract)
Green Tone Reproduction Curve   : (Binary data 14 bytes, use -b option to extract)
Blue Tone Reproduction Curve    : (Binary data 14 bytes, use -b option to extract)
Red Matrix Column               : 0.79767 0.28804 0
Green Matrix Column             : 0.13519 0.71188 0
Blue Matrix Column              : 0.03134 9e-005 0.82491
Device Mfg Desc                 : KODAK
Device Model Desc               : Reference Output Medium Metric(ROMM)
Make And Model                  : (Binary data 40 bytes, use -b option to extract)
4

1 に答える 1

7

これがすべての画像に当てはまるかどうかはわかりません。少なくとも私が持っている画像には、この情報が「プロパティ」にあります。したがって、印刷可能なプロファイル名を取得するには、次のように機能する必要があります。

$imagick = new imagick('/some/filename');
$profile = $imagick->getImageProperties('icc:model', true);
/**
 * If the property 'icc:model' is set $profile now should be:
 * array( 'icc:model' => 'ICC model name')
 */

画像に設定されているすべてのプロパティを確認したい場合は、 を使用して画像を手動でプローブできますidentify -verbose /some/filename。そこで「Properties:」を探す必要があります。そこで ICC 名を設定する必要があります。

上記は、ICC プロファイル名を取得する簡単な方法です。ICC プロファイルからの ICC 名が本当に必要な場合は、ICC プロファイル フォーマット仕様を参照してください。

要するに:

  • 最初の 128 バイトはヘッダーです。次に、タグ テーブルが続きます。最初の 4 バイトはテーブルのサイズです。
  • 各タグは 4 バイトのトリプレットで構成されます。最初の 4 バイトはタグの名前です。次の 4 バイトは、icc ファイル内のデータのオフセットです。次の 4 バイトは、タグ データのサイズを定義します。

「desc」タグに関心があります (仕様の 63 ページを参照)。

  • 説明自体は再び「desc」で始まり、4 バイトが予約されています。次の 4 バイトは、ICC プロファイル名のサイズを定義します。

コードでは、次のように機能します。

$image = new imagick('/path/to/img');
try {
    $existingICC = $image->getImageProfile('icc');
} catch (ImagickException $e) {
    // Handle it
    $existingICC = null;
}

if($existingICC) {
    // Search the start of the description tag in the tag table.:
    // We are not looking in the 128 bytes for the header + 4 bytes for the size of the table
    $descTagPos = stripos( $existingICC, 'desc', 131 );
    if( $descTagPos === false) {
       // There is no description, handle it.
    } else {
        // This is the description Tag ( 'desc'|offset|size each with a size of 4 bytes
        $descTag = substr( $existingICC, $descTagPos, 12 );

        // Get the offset out of the description tag, unpack it from binary to hex and then from hex to decimal
        $descTagOffset = substr ( $descTag, 4, 4 );
        $descTagOffset = unpack( 'H*', $descTagOffset );
        $descTagOffset = hexdec( $descTagOffset[1] );

        // Same for the description size
        $descTagSize = substr ( $existingICC, $descTagPos + 8, 4 );
        $descTagSize = unpack('H*', $descTagSize);
        $descTagSize = hexdec( $descTagSize[1] );

        // Here finally is the descripton
        $iccDesc = substr( $existingICC, $descTagOffset, $descTagSize );

        // See page 63 in the standard, here we extract the size of the ICC profile name string
        $iccNameSize = substr( $iccDesc, 8, 4 );
        $iccNameSize = unpack( 'H*', $iccNameSize);
        $iccNameSize = hexdec( $iccNameSize[1]);

        // Finally got the name.
        $iccName = substr( $iccDesc, 12, $iccNameSize );
        echo "ICC name: $iccName\n";
    }
}
于 2015-05-21T10:04:58.617 に答える