encode($img, "png"); // Compare to known-good PNG $this -> assertEquals(self::SMALL_FILE, $pngStr); } public function testDecode() { $codec = new PngCodec(); $img = $codec -> decode(self::SMALL_FILE); $this -> assertTrue($img instanceof RgbRasterImage); $this -> assertEquals(1, $img -> getWidth()); $this -> assertEquals(1, $img -> getHeight()); } public function testBlackAndWhiteImageLoad() { // Simple test of a black-and-white, interlaced & non-interlaced image, since // we can do a text-based assertion on the actual image content. $expected = " ▄█\n" . " ▄███\n" . " ██ ██ ▄█████\n" . " ██ ▄▄ ██ ▄███████\n" . " ██ ██ ██ ▄█████████\n" . " ████████ ▄███████████\n" . " ██ ██ ▄█████████████\n" . " ▄███████████████\n" . " ▄█████████████████\n" . " ▄███████ █████\n" . " ▄█████████ ████ ████\n" . " ▄███████████ █████\n" . " ▄█████████████ ████ ████\n" . " ▄███████████████ █████\n" . " ▄█████████████████████████████\n" . "▄███████████████████████████████\n"; // Load interlaced & non-interlaced $interlacedImage = Image::fromFile(__DIR__ . "/../../resources/pngsuite/basi0g01.png"); $interlacedResult = $interlacedImage -> toString(); $nonInterlacedImage = Image::fromFile(__DIR__ . "/../../resources/pngsuite/basn0g01.png"); $nonInterlacedResult = $nonInterlacedImage -> toString(); // These should both match the expected output $this -> assertEquals($expected, $interlacedResult); $this -> assertEquals($expected, $nonInterlacedResult); } public function testIndexedImageLoad() { // Load an interlaced 8-bit image, which follows a very different code path to // lower bit depths. $img = Image::fromFile(__DIR__ . "/../../resources/pngsuite/basi3p08.png") -> toIndexed(); $this -> assertEquals(255, $img -> getMaxVal()); $this -> assertEquals(32, $img -> getWidth()); $this -> assertEquals(32, $img -> getHeight()); } public function testFiltering() { // Expected value is sensitive to the grayscale -> B&W conversion $expected = "████████████████████████████████\n" . "███████████▀▀▀▀▀▀▀▀▀▀███████████\n" . "████████▀ ▀████████\n" . "██████▀ ▀██████\n" . "████▀ ▀████\n" . "███▀ ▀███\n" . "███ ███\n" . "███ ███\n" . "███ ███\n" . "███ ███\n" . "███▄ ▄███\n" . "████▄ ▄████\n" . "██████▄ ▄██████\n" . "████████▄ ▄████████\n" . "███████████▄▄▄▄▄▄▄▄▄▄███████████\n" . "████████████████████████████████\n"; // Image with different filters on each scanline $img = Image::fromFile(__DIR__ . "/../../resources/pngsuite/f99n0g04.png") -> toBlackAndWhite(); $result = $img -> toString(); $this -> assertEquals($expected, $result); } }