23 $png_signature = pack(
"C8", 137, 80, 78, 71, 13, 10, 26, 10);
25 $header = substr($this->_contents, 0, 8);
26 if (
$header != $png_signature) {
27 echo
'This is not a valid PNG image';
29 $this->_size = strlen($this->_contents);
30 $this->_chunks =
array();
34 $chunk = @unpack(
'Nsize/a4type', substr($this->_contents, $position, 8));
35 $this->_chunks[$chunk[
'type']][] = substr($this->_contents, $position + 8, $chunk[
'size']);
37 $position += $chunk[
'size'] + 12;
38 }
while ($position < $this->_size);
52 if (array_key_exists(
$type, $this->_chunks)) {
53 foreach (array_keys($this->_chunks[
$type]) as $typekey) {
54 list(
$key,
$data) = explode(
"\0", $this->_chunks[$type][$typekey]);
55 if (strcmp(
$key, $check) == 0) {
56 echo
'Key "' . $check .
'" already exists in "' . $type .
'" chunk.';
75 $chunkData =
$key .
"\0" . $value;
76 $crc = pack(
"N", crc32($chunkType . $chunkData));
77 $len = pack(
"N", strlen($chunkData));
79 $newChunk = $len . $chunkType . $chunkData . $crc;
80 $result = substr($this->_contents, 0, $this->_size - 12)
82 . substr($this->_contents, $this->_size - 12, 12);
98 $retval = substr($png, 0, 8);
100 if ($retval !=
"\x89PNG\x0d\x0a\x1a\x0a") {
101 throw new Exception(
'Is not a valid PNG image');
104 $chunkHeader = substr($png, $ipos, 8);
106 while ($chunkHeader) {
108 $chunk = @unpack(
'Nsize/a4type', $chunkHeader);
110 if ($chunk[
'type'] == $chunkType) {
111 $data = substr($png, $ipos, $chunk[
'size']);
112 $sections = explode(
"\0",
$data);
114 if ($sections[0] ==
$key) {
119 $data = substr($png, $ipos, $chunk[
'size']+4);
120 $ipos = $ipos + $chunk[
'size'] + 4;
123 $retval = $retval . $chunkHeader .
$data;
126 $chunkHeader = substr($png, $ipos, 8);
145 $retval = substr($png, 0, 8);
147 if ($retval !=
"\x89PNG\x0d\x0a\x1a\x0a") {
152 $chunkHeader = substr($png, $ipos, 8);
154 while ($chunkHeader) {
156 $chunk = @unpack(
'Nsize/a4type', $chunkHeader);
158 if ($chunk[
'type'] ==
'tEXt') {
159 $data = substr($png, $ipos, $chunk[
'size']);
160 $sections = explode(
"\0",
$data);
161 if ($sections[0] ==
$key) {
166 $data = substr($png, $ipos, $chunk[
'size']+4);
167 $ipos = $ipos + $chunk[
'size'] + 4;
170 $chunkHeader = substr($png, $ipos, 8);
Php library to Bake the PNG Images.
__construct($contents)
Prepares file for handling metadata.
addChunk($chunkType, $key, $value)
Add a chunk by type with given key and text.
Create styles array
The data for the language used.
removeChunks($chunkType, $key, $png)
removes a chunk by type with given key and text
extractBadgeInfo($png, $key='openbadges')
Extracts the baked PNG info by the Key.
checkChunks($type, $check)
Checks if a key already exists in the chunk of said type.