= W-1) { $x = 0; $y++; } else { $x++; } } function encode(string $letter): array { global $alphabet; $letter = strtoupper($letter); $n = strpos($alphabet, $letter); if ($n === false) throw new Exception("letter $letter not found in the alphabet"); $ab = []; for ($i = 0; $i < 5; $i++) $ab[] = ($n >> $i) & 0x01; return array_reverse($ab); } $a = imagecolorallocate($img, 0xcc, 0xcc, 0xcc); $b = imagecolorallocate($img, 0x99, 0x99, 0x99); for ($i = 0; $i < strlen($plaintext); $i++) { $c = $plaintext[$i]; if ($c == ' ') { for ($j = 0; $j < 5; $j++) move_cursor(); continue; } foreach (encode($c) as $bit) { imagesetpixel($img, $x, $y, $bit ? $b : $a); move_cursor(); } } imagepng($img, '/tmp/4in1_fav.png');