I am not sure if this applies to all images. At least the images that I have have this information in their βPropertiesβ. Thus, in order to get the name for the printed profile, it should work as follows:
$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') */
If you want to see all the properties that are set for an image, you can examine the image manually using identify -verbose /some/filename . There you need to look for "Properties:", the name of the ICC should be indicated there.
The above method is to get the ICC profile name. If you really need the ICC name from the icc profile, you can take a look at the ICC profile specification
In short:
- The first 128 bytes is the header. This is followed by a tag table, where the first 4 bytes represent the size of the table.
- Each tag consists of 4 byte triplets. The first 4 bytes is the name of the tag. The next four bytes are the data offset in the icc file. The next four bytes determine the size of the tag data.
We are interested in the tag "desc" (see page 63 in the specification).
- The description itself starts again with "desc", then four bytes are reserved. The next four bytes determine the size of the ICC profile name.
In code, it works as follows:
$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"; } }
Darokthar
source share