width = $width; $this->height = $height; $this->bitDepth = $bitDepth; $this->colorType = $colorType; $this->compression = $compression; $this->filter = $filter; $this->interlace = $interlace; } public function addPalette(RgbPaletteEntry $rgbPaletteEntry): self { $this->plte[] = $rgbPaletteEntry; return $this; } public function getWidth(): int { return $this->width; } public function getHeight(): int { return $this->height; } public function getBitDepth(): int { return $this->bitDepth; } public function getColorType(): int { return $this->colorType; } public function getCompression(): int { return $this->compression; } public function getFilter(): int { return $this->filter; } public function getInterlace(): int { return $this->interlace; } /** * @return RgbPaletteEntry[] */ public function getPlte(): array { return $this->plte; } public static function createFromArray(array $data): self { $data = Utils::filterNullValues($data); foreach (['width', 'compression', 'height', 'bitDepth', 'colorType', 'compression', 'filter', 'interlace'] as $key) { Assertion::keyExists($data, $key, sprintf('Invalid data. The key "%s" is missing', $key)); } $object = new self( $data['width'], $data['height'], $data['bitDepth'], $data['colorType'], $data['compression'], $data['filter'], $data['interlace'] ); if (isset($data['plte'])) { $plte = $data['plte']; Assertion::isArray($plte, Utils::logicException('Invalid "plte" parameter')); foreach ($plte as $item) { $object->addPalette(RgbPaletteEntry::createFromArray($item)); } } return $object; } public function jsonSerialize(): array { $data = [ 'width' => $this->width, 'height' => $this->height, 'bitDepth' => $this->bitDepth, 'colorType' => $this->colorType, 'compression' => $this->compression, 'filter' => $this->filter, 'interlace' => $this->interlace, 'plte' => $this->plte, ]; return Utils::filterNullValues($data); } }