This is a bit strange request :)
So, you would like to use php-gd to get started. This is usually included when installing php on any OS with a decent repo, but just remember that this is not for you, you can get installation instructions here;
http://www.php.net/manual/en/image.setup.php
First, we need to figure out how large the image will be in width; height, obviously, will always be one.
So,
$str = $_GET['str']; $img_width = strlen($str);
strlen will tell us how many characters there are in the string $ str, and since we give one pixel per character, the number of characters will give us the required width.
To facilitate access, divide the string into an array - with each element for each individual pixel.
$color_array = str_split($str);
Now set up the "pointer" for which we draw a pixel. This is php, so you DON'T NEED to do this, but it's nice to be careful.
$current_px = (int) 0;
And now you can initialize GD and start making an image;
$im = imagecreatetruecolor($img_width, 1); // Initialise colours; $black = imagecolorallocate($im, 0, 0, 0); $white = imagecolorallocate($im, 255, 255, 255); // Now, start running through the array foreach ($color_array as $y) { if ($y == 1) { imagesetpixel ( $im, $current_px , 1 , $black ); } $current_px++; // Don't need to "draw" a white pixel for 0. Just draw nothing and add to the counter. }
This will draw your image, then all you need to do is display it;
header('Content-type: image/png'); imagepng($im); imagedestroy($im);
Note that the $ white declaration is not needed at all - I just left it to give you an idea of how you declare different colors with gd.
You will probably have to debug this a bit before using it - this has been a long time since I used GD. Anyway, hope this helps!