protected function getImage() { $image = new \Imagick(); $image->newImage(2, 2, new \ImagickPixel('white')); $draw = new \ImagickDraw(); $draw->setFillColor(new \ImagickPixel('black')); $draw->color(0, 1, \Imagick::PAINT_POINT); $draw2 = new \ImagickDraw(); $draw2->setFillColor(new \ImagickPixel('black')); $draw2->color(1, 1, \Imagick::PAINT_POINT); $image->drawImage($draw); $image->drawimage($draw2); $image->setformat('png'); return $image; }
$maxX = $matches[4]; $maxY = $matches[5]; for ($x = $minX; $x <= $maxX; $x++) { for ($y = $minY; $y <= $maxY; $y++) { switch ($action) { case 'turn on': $grid[$x][$y] = true; break; case 'turn off': $grid[$x][$y] = false; break; case 'toggle': $grid[$x][$y] = !$grid[$x][$y]; } } } } } $draw = new ImagickDraw(); $draw->setfillcolor(new ImagickPixel('white')); foreach ($grid as $x => $col) { foreach ($col as $y => $px) { if ($px) { $draw->color($x, $y, Imagick::PAINT_POINT); } } } $image = new Imagick(); $image->newimage(count($grid), count($grid[0]), 'black', 'png'); $image->drawimage($draw); $image->writeimage('output.png');