I want to be able create a PPM file from text using PHP that can be displayed on an RGB LED matrix display. That means I need to build the image pixel-by-pixel, row-by-row. I managed to do it using one character as input. I want to able to do it with multiple special and non-special characters. I have working code for setting the header, dimensions etc. of the PPM automatically so the whole story above is irrelevant. It is only for your information if you would like to understand why I need this.
$input = "ABC DE";
Character sets are given. For letter 'A', it looks like this (6x10 font + 1px space after each row so text can be fed continuously):
$a0 = ($black.' '.$black.' '.$color.' '.$color.' '.$black.' '.$black.' '.$space);
$a1 = ($black.' '.$color.' '.$black.' '.$black.' '.$color.' '.$black.' '.$space);
$a2 = ($color.' '.$black.' '.$black.' '.$black.' '.$black.' '.$color.' '.$space);
$a3 = ($color.' '.$black.' '.$black.' '.$black.' '.$black.' '.$color.' '.$space);
$a4 = ($color.' '.$black.' '.$black.' '.$black.' '.$black.' '.$color.' '.$space);
$a5 = ($color.' '.$color.' '.$color.' '.$color.' '.$color.' '.$color.' '.$space);
$a6 = ($color.' '.$black.' '.$black.' '.$black.' '.$black.' '.$color.' '.$space);
$a7 = ($color.' '.$black.' '.$black.' '.$black.' '.$black.' '.$color.' '.$space);
$a8 = ($color.' '.$black.' '.$black.' '.$black.' '.$black.' '.$color.' '.$space);
$a9 = ($color.' '.$black.' '.$black.' '.$black.' '.$black.' '.$color.' '.$space);
If I echo the above in order,
$output = ($a0.' '.$a1.' '.$a2.' '.$a3.' '.$a4.' '.$a5.' '.$a6.' '.$a7.' '.$a8.' '.$a9);
it will give letter 'A'.
For letter 'B', it looks like this (and so on):
$b0 = ($color.' '.$color.' '.$color.' '.$color.' '.$black.' '.$black.' '.$space);
$b1 = ($color.' '.$black.' '.$black.' '.$black.' '.$color.' '.$black.' '.$space);
$b2 = ($color.' '.$black.' '.$black.' '.$black.' '.$black.' '.$color.' '.$space);
$b3 = ($color.' '.$black.' '.$black.' '.$black.' '.$color.' '.$black.' '.$space);
$b4 = ($color.' '.$color.' '.$color.' '.$color.' '.$black.' '.$black.' '.$space);
$b5 = ($color.' '.$black.' '.$black.' '.$black.' '.$color.' '.$black.' '.$space);
$b6 = ($color.' '.$black.' '.$black.' '.$black.' '.$black.' '.$color.' '.$space);
$b7 = ($color.' '.$black.' '.$black.' '.$black.' '.$black.' '.$color.' '.$space);
$b8 = ($color.' '.$black.' '.$black.' '.$black.' '.$color.' '.$black.' '.$space);
$b9 = ($color.' '.$color.' '.$color.' '.$color.' '.$black.' '.$black.' '.$space);
If I wanted to print 'AB', I need to do it row-by-row:
$output = ($a0.' '.$b0.' '.$a1.' '.$b1.' '.$a2.' '.$b2.' '.$a3.' '.$b3.' '.$a4.' '.$b4.' '.$a5.' '.$b5.' '.$a6.' '.$b6.' '.$a7.' '.$b7.' '.$a8.' '.$b8.' '.$a9.' '.$b9);
'ABC DE' would be:
$output = ($a0.' '.$b0.' '.$c0.' '.$space0.' '.$d0.' '.$e0.' '.$a1.' '.$b1.' '.$c1.' '.$space1.' '.$d1.' '.$e1 ...........
How do I process the $input text so I get the above? I know I need to count the total number of characters then start building the text character-by-character/row-by-row. I have working code for the rest, only the part above is missing. Please let me know if you require more information.