diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5008ddfcf53c02e82d7eee2e57c38e5672ef89f6 GIT binary patch literal 6148 zcmZQzU|@7AO)+F(5MW?n;9!8z45|!R0Z1N%F(jFgL>QrFAPJ2!M?+vV1V%$(Gz3ON zU^D~25V%SxcdJP zRior+2#kinunYl47MEZbCs3t{!+W4QHvuXKVuPw;Mo^s$(F3lEVT}ML$bg~*R5_@+ b2Uo?6kTwK}57Iu`5P${HC_Nei0}uiLNUI8I literal 0 HcmV?d00001 diff --git a/.htaccess b/.htaccess new file mode 100644 index 0000000..f30148f --- /dev/null +++ b/.htaccess @@ -0,0 +1,3 @@ +RewriteEngine on + +RewriteRule ^demo$ index.php?phrase=JP+Hastings-Spital&theme=Rainbow&method=ASCII&offset=0&spread=0&bs=40&width=8&save=0 [L] \ No newline at end of file diff --git a/BnW.theme b/BnW.theme new file mode 100644 index 0000000..8572469 --- /dev/null +++ b/BnW.theme @@ -0,0 +1,16 @@ +0,0,0 +17,17,17 +34,34,34 +51,51,51 +68,68,68 +85,85,85 +102,102,102 +119,119,119 +136,136,136 +153,153,153 +170,170,170 +187,187,187 +204,204,204 +221,221,221 +238,238,238 +255,255,255 diff --git a/Dark Fire.theme b/Dark Fire.theme new file mode 100644 index 0000000..6b106db --- /dev/null +++ b/Dark Fire.theme @@ -0,0 +1,16 @@ +127,0,0 +144,0,0 +161,0,0 +178,0,0 +195,0,0 +212,0,0 +229,0,0 +246,0,0 +255,17,0 +255,51,0 +255,85,0 +255,119,0 +255,153,0 +255,187,0 +255,221,0 +255,255,0 \ No newline at end of file diff --git a/Fire.theme b/Fire.theme new file mode 100644 index 0000000..d0b988a --- /dev/null +++ b/Fire.theme @@ -0,0 +1,16 @@ +255,0,0 +255,17,0 +255,34,0 +255,51,0 +255,68,0 +255,85,0 +255,102,0 +255,119,0 +255,136,0 +255,153,0 +255,170,0 +255,187,0 +255,204,0 +255,221,0 +255,238,0 +255,255,0 \ No newline at end of file diff --git a/Matrix.theme b/Matrix.theme new file mode 100644 index 0000000..6feda63 --- /dev/null +++ b/Matrix.theme @@ -0,0 +1,16 @@ +0,0,0 +0,17,0 +0,34,0 +0,51,0 +0,68,0 +0,85,0 +0,102,0 +0,119,0 +0,136,0 +0,153,0 +0,170,0 +0,187,0 +0,204,0 +0,221,0 +0,238,0 +0,255,0 \ No newline at end of file diff --git a/Purple Turtle.theme b/Purple Turtle.theme new file mode 100644 index 0000000..8aa6532 --- /dev/null +++ b/Purple Turtle.theme @@ -0,0 +1,16 @@ +0,0,127 +0,0,153 +0,0,178 +0,0,204 +0,0,229 +0,0,255 +51,0,204 +102,0,153 +153,0,102 +204,0,51 +255,0,0 +229,0,0 +204,0,0 +178,0,0 +153,0,0 +127,0,0 \ No newline at end of file diff --git a/Rainbow.theme b/Rainbow.theme new file mode 100644 index 0000000..600d8a6 --- /dev/null +++ b/Rainbow.theme @@ -0,0 +1,16 @@ +0,51,204 +51,0,153 +102,0,153 +153,0,153 +204,0,153 +255,0,0 +255,85,0 +255,170,0 +255,255,0 +205,255,0 +153,255,0 +51,255,0 +0,204,0 +0,179,102 +0,153,153 +0,102,179 \ No newline at end of file diff --git a/Seeing Red.theme b/Seeing Red.theme new file mode 100644 index 0000000..e40070d --- /dev/null +++ b/Seeing Red.theme @@ -0,0 +1,16 @@ +0,0,0 +17,0,0 +34,0,0 +51,0,0 +68,0,0 +85,0,0 +102,0,0 +119,0,0 +136,0,0 +153,0,0 +170,0,0 +187,0,0 +204,0,0 +221,0,0 +238,0,0 +255,0,0 diff --git a/Sky.theme b/Sky.theme new file mode 100644 index 0000000..67e6e61 --- /dev/null +++ b/Sky.theme @@ -0,0 +1,16 @@ +0,0,255 +17,17,255 +34,34,255 +51,51,255 +68,68,255 +85,85,255 +102,102,255 +119,119,255 +136,136,255 +153,153,255 +170,170,255 +187,187,255 +204,204,255 +221,221,255 +238,238,255 +255,255,255 \ No newline at end of file diff --git a/Windows 3.11.theme b/Windows 3.11.theme new file mode 100644 index 0000000..ca35c11 --- /dev/null +++ b/Windows 3.11.theme @@ -0,0 +1,16 @@ +0,0,0 +85,85,85 +0,0,170 +85,85,255 +0,170,0 +85,170,85 +0,170,170 +85,170,170 +170,0,0 +170,85,85 +170,0,170 +170,85,170 +170,85,0 +255,255,85 +170,170,170 +255,255,255 \ No newline at end of file diff --git a/index.php b/index.php new file mode 100644 index 0000000..a983b4b --- /dev/null +++ b/index.php @@ -0,0 +1,389 @@ + + + +ColourFul Encoder + + + + Toys by JP +

ColourFul

+ + $max) + $phrase = substr($phrase,0,$max); + +if ($phrase != "") { + $blocksize = (is_numeric($_GET['_bs'])) ?$_GET['_bs'] : ((is_numeric($_GET['bs'])) ? min(75,$_GET['bs']) : 40); + + $theme = (in_array($_GET['theme'],array_keys($themes))) ? $_GET['theme'] : "Rainbow"; + + $code = ""; + + switch($_GET['method']) { + case "Alphanumeric": + $requiredcolours = 6; + $phrase = trim(preg_replace("![^a-z^0-9]!","",strtolower($phrase))); + $chrs = preg_split('//', $phrase, -1, PREG_SPLIT_NO_EMPTY); + $comment = "a-z, 0-9"; + foreach ($chrs as $chr) { + if (preg_match("![a-z]!",$chr)) { + $minicode = ord($chr) - ord("a"); + } elseif (preg_match("![0-9]!",$chr)) { + $minicode = 26 + $chr; + } + $code.=decbase($minicode,$requiredcolours); + } + break; + + case "URL": + $requiredcolours = 7; + function matchurlencode($matches) { + return strtolower(urlencode($matches[0])); + } + $phrase = trim(preg_replace_callback("![^a-z^0-9^\\$^\%^&^\+^-^\.^/^:^;^=^\?^@^_]!",'matchurlencode',strtolower($phrase))); + $chrs = preg_split('//', $phrase, -1, PREG_SPLIT_NO_EMPTY); + + $comment = "a-z 0-9 $ % & + - . / : = ? @ _"; + $extras = array("$"=>0,"%"=>1,"&"=>2,"+"=>3,"-"=>4,"."=>5,"/"=>6,":"=>7,"="=>8,"?"=>9,"@"=>10,"_"=>11); + foreach ($chrs as $chr) { + if (preg_match("![a-zA-Z]!",$chr)) { + $minicode = ord($chr) - ord("a"); + } elseif (preg_match("![0-9]!",$chr)) { + $minicode = 27 + $chr; + } else { + $minicode = 37 + $extras[$chr]; + } + $code.=decbase($minicode,$requiredcolours); + } + break; + + case "Integer": + $requiredcolours = 10; + $phrase = trim(preg_replace("![^0-9]!","",$phrase)); + $chrs = preg_split('//', $phrase, -1, PREG_SPLIT_NO_EMPTY); + $comment = "0-9"; + foreach ($chrs as $chr) { + $code.=$chr; + } + break; + + case "ASCII": + default: + $chrs = preg_split('//', trim($phrase), -1, PREG_SPLIT_NO_EMPTY); + $requiredcolours = 16; + $comment = "All ASCII characters (by their reference number)"; + foreach ($chrs as $chr) { + $code.=str_pad(dechex(ord($chr)),2,0,STR_PAD_LEFT); + } + } + + $code = preg_split('//', $code, -1, PREG_SPLIT_NO_EMPTY); + if ($phrase != "") { + + $possibleWidths = array(); + for($possibleWidth=count($code);$possibleWidth >= sqrt(count($code));$possibleWidth--) { + if (count($code) % $possibleWidth == 0) + $possibleWidths[$possibleWidth] = $possibleWidth; + } + $square = end($possibleWidths); + + foreach(array_reverse($possibleWidths) as $p) { + $w = count($code) / $p; + $possibleWidths[$w] = $w; + } + + $width = (in_array($_GET['width'],$possibleWidths)) ? $_GET['width'] : $square; + + $height = count($code) / $width; + + if ($height*$blocksize < $requiredcolours) { + $blocksize = ceil($requiredcolours/$height); + } + + $key = ($height*$blocksize) / ($requiredcolours); + + $key = ($_GET['strict'] == 1) ? floor($key) : $key; + + $img = imagecreatetruecolor($width*$blocksize + $key+1,$height*$blocksize); + + $colours = array(); + $thistheme = $themes[$theme]; + + $offset = (($_GET['offset'] >= 0 and $_GET['offset'] <= 16) ? $_GET['offset'] : 0); + + for($ii=0;$ii<$offset;$ii++) { + $thistheme[] = array_shift($thistheme); + } + + $thistheme = doSpread($thistheme,$_GET['spread']); + + $black = imagecolorallocate($img, 0, 0, 0); + foreach($thistheme as $i=>$allcolour) { + if ($i >= $requiredcolours) + break; + $c = explode(",",$allcolour); + $colours[] = imagecolorallocate($img,$c[0],$c[1],$c[2]); + + } + + foreach($code as $i=>$colour) { + $colour = hexdec($colour); + paint($i,$img,$colours[$colour]); + } + + foreach(array_merge($colours,array($black)) as $i=>$colour) { + imagefilledrectangle($img, $width * $blocksize + 1, $i * $key, $width * $blocksize + $key, ($i+1) * $key, $colour); + } + imageline($img, $width * $blocksize, 0, $width * $blocksize, $height * $blocksize, $black); + + $fname = explode(" ",$phrase); + $fname = preg_replace("!_{2,}!", "_", preg_replace("!\W!", "_", $fname[0])); + + ob_start(); + imagepng($img); + $image = base64_encode(ob_get_contents()); + ob_end_clean(); + + ?> + +
+ + + Ooops, with that conversion method there are no characters to convert! + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Phrase: [ chars]
Width: blocks
Height: blocks
Block Size: px
Key Width:~ px
Character Conversion:
Image URL:
+
+ +
+ + + + + + + + +
+ + + Palette:
+ Conversion Method: +
+ Offset: + Spread:
+ Block Size: >Add Colour Aid
+ Dimensions: +
+ +
+
+ +
+

Why?

+

I wanted to build a way of turning text into something (vaguely) pretty, devoid of obvious meaning but easily reformed back into text by hand — this is what I came up with!

+ +

How?

+
    +
  1. A range of letters will be converted. At the moment there are four ranges: ASCII, URL, (positive) integer and (case insensitive) alphanumeric.
  2. +
  3. Each character is converted into a number according to the chosen method (The number is represented in either base 6 (Alphanumeric), 7 (URL), 10 (Integer) or 16 (ASCII) depending on the method).
  4. +
  5. More than 16 colours can be hard to tell apart, so for clarity all except the numerical method split each character number into two numbers. eg. 255 in base 16 (ASCII) becomes [ 16, 16 ]; 27 in base 7 (URL) becomes [ 3, 6 ] — have a look at bases on the wikipedia for more info.
  6. +
  7. Each number is now converted to a colour according to the selections you make
  8. +
  9. The colours are laid out in order (in a rectangle), and a 'key' is placed on the right so you can convert the colours back into numbers (the top colour = 0, the next = 1 and so on).
  10. +
  11. You have a colourful picture that has a clearly interpretable message inside it!
  12. +
+

Notes about the conversion methods

+

NB. Look at the 'character conversion' information above, it gives you the list of characters in order so you can convert back from a coloursheet

+
    +
  • ASCII is one of the original charcter indexing schemes where every character needed (at the time) was given a number ('a' is 97 for example). There are alot of useless characters, so your message make look strange.
  • +
  • Alphanumeric only allows the letters a-z (which become 0-26) and numbers (that become 27-36) which means they can be described by two base-6 numbers, so two squares = one character with 6 different colours for each square.
  • +
  • URLs only have a certain number of allowed characters. I picked the alphabet, numbers and 13 most popular symbols (arranged in ASCII order) to make 49 symbols. This makes two base-7 numbers, therefore two squares are one character and there are 7 possible colours for each square. You can enter any character, but if it is not present in the above 49 it will be urlencoded and will look like: %20 (which is a space).
  • +
  • Integer is as it sounds, there are 10 colours, the first is 0, the last is 9!
  • +
+ += 16) { + global $colours; + + for($i=0;$i<$requiredcolours;$i++) { + //$the_y = ($y % 2) ? ($y+1) * $blocksize - 1 : $y * $blocksize; + //imagesetpixel($img,$x*$blocksize + $i,$the_y,$colours[$i]); + if (($x % 2)) + imagesetpixel($img,$x*$blocksize,$y*$blocksize + $i,$colours[$i]); + if (($x+1 == $width) and !($x % 2)) + imagesetpixel($img,($x+1)*$blocksize-1,$y*$blocksize + $i,$colours[$i]); + } + } +} + +function listThemes() { + $themes = array(); + if ($handle = opendir("./")) { + while (false !== ($file = readdir($handle))) { + $path = pathinfo($file); + if ($path['extension'] == "theme") { + $themes[substr($path['basename'],0,-6)] = explode("\n", file_get_contents($file)); + } + } + closedir($handle); + } + return $themes; +} + +function decbase($number,$base) { + $a = dechex(floor($number / $base)); + $b = dechex($number % $base); + return $a.$b; +} + +function doSpread($thistheme,$spread) { + switch($spread) { + case 2: + for($i=1;$i<16;$i+=3) { + $thistheme[] = $thistheme[$i]; + unset($thistheme[$i]); + } + $thistheme = array_values($thistheme); + for($i=1;$i<16;$i+=2) { + $thistheme[] = $thistheme[$i]; + unset($thistheme[$i]); + } + break; + case 1: + for($i=1;$i<16;$i+=2) { + $thistheme[] = $thistheme[$i]; + unset($thistheme[$i]); + } + break; + } + return array_values($thistheme); +} +?> +
+ + + + -- 2.51.2 From 7d0790bdfb943648b710154eaadac3dd6884904c Mon Sep 17 00:00:00 2001 From: JP Hastings-Spital Date: Tue, 2 Oct 2012 07:18:36 +0100 Subject: [PATCH 2/2] Stupid DS_Store --- .DS_Store | Bin 6148 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index 5008ddfcf53c02e82d7eee2e57c38e5672ef89f6..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmZQzU|@7AO)+F(5MW?n;9!8z45|!R0Z1N%F(jFgL>QrFAPJ2!M?+vV1V%$(Gz3ON zU^D~25V%SxcdJP zRior+2#kinunYl47MEZbCs3t{!+W4QHvuXKVuPw;Mo^s$(F3lEVT}ML$bg~*R5_@+ b2Uo?6kTwK}57Iu`5P${HC_Nei0}uiLNUI8I