<?php

#
# Purpose : translates ascii characters a-z to their braille symbol.
# See also: ascii2braille2.phps
#

# Draws the grid to divide the sections
function drawGrid(&$image, &$color) {
    return
        
# Horizontal lines
        
imageline($image0339933$color) &
        
imageline($image0669966$color) &

        
# Vertical lines
        
imageline($image3399330$color) &
        
imageline($image6699660$color)
    ;
}

# Main function
function ascii2braille($char) {
    
# Position coords (for reference)
    
$coords = array(
        
'top' => array(00340),
        
'mid' => array(0343434),
        
'btm' => array(0673467)
    );

    
# The braille alphabet
    
$braille = array(
        
97 => array(00),
        array(
00034),
        array(
00340),
        array(
003403434),
        array(
003434),
        array(
00340034),
        array(
003400343434),
        array(
000343434),
        array(
340034),
        array(
3400343434),
        array(
00067),
        array(
00034067),
        array(
00340067),
        array(
003403434067),
        array(
003434067),
        array(
00340034067),
        array(
003400343434067),
        array(
000343434067),
        array(
340034067),
        array(
3400343434067),
        array(
000673467),
        array(
000670343467),
        array(
34003434343467),
        array(
003400673467),
        array(
0034034340673467),
        array(
0034340673467)
    );

    
# Create the resource
    
$image imagecreatetruecolor(6699);

    
# Define colors
    
$black imagecolorallocate($image000);
    
$white imagecolorallocate($image255255255);
    
    
# Set the background color
    
imagefill($image00$white);

    
# Draw grid
    
drawGrid($image$black);

    
$data $braille[ord($char)];
    for (
$i 0$n count($data); $i $n$i+=2) {
        
$x $data[$i];
        
$y $data[$i+1];
        
imagefill($image$x$y$black);
    }

    
# Reset grid color
    
drawGrid($image$white);

    
# Display
    
header('Content-type: image/png'); 
    
imagepng($image);
    
imagedestroy($image);
}

# Calling example
ascii2braille('a');

?>