Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>That's a little bit of a strange request :)</p> <p>So, what you'd want to use here is php-gd, for a start. Generally this is included when installing php on any OS with decent repo's, but just incase it isn't for you, you can get the installation instructions here;</p> <p><a href="http://www.php.net/manual/en/image.setup.php" rel="nofollow">http://www.php.net/manual/en/image.setup.php</a></p> <p>First, we'll need to figure out exactly how big the image will need to be in width; height will obviously always be one.</p> <p>So;</p> <pre><code>$str = $_GET['str']; $img_width = strlen($str); </code></pre> <p>strlen will tell us how many characters are in the $str string, and since we're giving one pixel per character, the amount of characters will give us the required width.</p> <p>For ease of access, split the string into an array - with each element for each separate pixel.</p> <pre><code>$color_array = str_split($str); </code></pre> <p>Now, let's set up a "pointer", for which pixel we're drawing to. It's php so you don't NEED to initalise this, but it's nice to be tidy.</p> <pre><code>$current_px = (int) 0; </code></pre> <p>And now you can initialise GD and start making the image;</p> <pre><code>$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. } </code></pre> <p>This will draw your image, then all you need do is display it;</p> <pre><code>header('Content-type: image/png'); imagepng($im); imagedestroy($im); </code></pre> <p>Note that the $white declaration isn't needed at all - I just left it in to give you an idea of how you declare different colours with gd.</p> <p>You'll probably need to debug this a bit before using it - it's been a long time since I've used GD. Anyway, hope this helps!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload