diff --git a/.gitignore b/.gitignore index d5a90de..d8909ad 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ input.txt -/.idea \ No newline at end of file +/.idea +/day_8/part_2.png diff --git a/day_8/part_1.php b/day_8/part_1.php new file mode 100644 index 0000000..9a799cd --- /dev/null +++ b/day_8/part_1.php @@ -0,0 +1,25 @@ + $line) { + $numbers = str_split($line); + foreach ($numbers as $col => $number) { + if ($final_image[$row][$col] == TRANSPARENT) { + $final_image[$row][$col] = $number; + } + } + } +} + +$image = new Imagick(); + +$white = new \ImagickPixel('#FFFFFF'); +$black = new \ImagickPixel('#000000'); + +$image->newImage(WIDTH * 10, HEIGHT * 10, 'none'); +$image->setImageFormat('png'); + +$draw = new \ImagickDraw(); + +foreach ($final_image as $j => $row) { + foreach ($row as $i => $cell) { + $color = 'none'; + if ($cell == WHITE) { + $color = $white; + } + if ($cell == BLACK) { + $color = $black; + } + $draw->setFillColor($color); + $draw->rectangle(10 * $i, 10 * $j, 10 * $i + 10, 10 * $j + 10); + } +} + +$image->drawImage($draw); + +header("Content-Type: image/png"); +$data = $image->getImageBlob(); +file_put_contents('part_2.png', $data);