Geting byte content & uInt32 encoding [solved]
Posted: Tue Sep 04, 2007 8:54 am
Hi all there
Have search for the following problem, but could find nothing that worked.
I have the following problem:
I have to detect color profiles which are embedded in different image file types. I have no big problem to find the beginning of the embedded data. And I know the architecture of the embedded profile.
Bytes 0..3 - Profile size - Encoded as UInt32Number
Bytes 16..19 - Colour space
I can get out the Colour space, but not the profile size. Which I need to extract the whole profile. I've tried the following:
If I open the file in a Hex-Editor I have no problem to search for the positions and then just transform the Hex-Code into Decimal. But I couldn't fix it in in PHP.
Have search for the following problem, but could find nothing that worked.
I have the following problem:
I have to detect color profiles which are embedded in different image file types. I have no big problem to find the beginning of the embedded data. And I know the architecture of the embedded profile.
Bytes 0..3 - Profile size - Encoded as UInt32Number
Bytes 16..19 - Colour space
I can get out the Colour space, but not the profile size. Which I need to extract the whole profile. I've tried the following:
Code: Select all
<?php
$filename = "./images/test.jpeg";
$fcontent = fopen($filename, "rb");
$fdata = fgets($fcontent, filesize($filename));
fclose($fcontent);
$profile_start = strpos($fdata,"ICC_PROFILE") //Detects the tag defining the start of the embedded content
$profile_start = $profile_start+11; //To start after the tag
$size = substr($fdata,$profile_start,4);
$colour_space = substr($fdata,$profile_start+16,4);
echo $size;
echo $colour_space;
?>