-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPNGChunk.php
More file actions
35 lines (30 loc) · 759 Bytes
/
Copy pathPNGChunk.php
File metadata and controls
35 lines (30 loc) · 759 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php
namespace SliveredMindOps\PNGParser;
require_once('Utils/Stream.php');
class PNGChunk {
//https://www.w3.org/TR/PNG/#5Chunk-layout
public $length;
public $type;
public $data;
public $crc;
public function __construct($stream)
{
$this->length = $stream->readUInt();
$this->type = $stream->readString(4);
if($this->length > 0){
$this->data = $stream->read($this->length);
}
$this->crc = $stream->read(4);
}
//pack data again
public function getData(){
$data = [];
$data = array_merge($data, unpack('C*', pack('N', $this->length)));
$data = array_merge($data, unpack('C*', $this->type));
if($this->length > 0){
$data = array_merge($data, $this->data);
}
$data = array_merge($data, $this->crc);
return $data;
}
}