Created
August 22, 2010 00:08
Revisions
-
dperini revised this gist
Aug 22, 2010 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,7 @@ <?php /* * Author: Diego Perini <[email protected]> * * this is what I have in my build system to embed * the packed version of NWMatcher in a PNG file; -
dperini revised this gist
Aug 22, 2010 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -12,7 +12,7 @@ * Here is the javascript decoder: * * // decodes and execute Javascript * // code embedded in a PNG8 image * function getDataPNG(g,k){ * var o;(o=new Image).src=g; * o.onload=function(){ -
dperini revised this gist
Aug 22, 2010 . 1 changed file with 23 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,13 +1,35 @@ <?php /* * Author: Diego Perini @[email protected] * * this is what I have in my build system to embed * the packed version of NWMatcher in a PNG file; * actually any data like JSON or XML can be * transported in compressed PNG files and * avoids HTTP compression requirements. * * Here is the javascript decoder: * * // decodes and execute Javascript * // code embedded in a PNG24 image * function getDataPNG(g,k){ * var o;(o=new Image).src=g; * o.onload=function(){ * var a,b,c,d,e,f='', * x=o.width,y=o.height; * c=document.createElement('canvas'); * e=c.getContext('2d');c.width=x;c.height=y; * e.drawImage(o,0,0);d=e.getImageData(0,0,x,y).data; * for(a=0;b=d[a];a+=4){f+=String.fromCharCode(b);}k(f)(); * }; * } * * // usage: * // forget about the toString.constructor * // just pass the path to your local js/png file * getDataPNG('dist/nwmatcher.png', toString.constructor); * */ $filename = 'dist/nwmatcher-pac.js'; -
dperini created this gist
Aug 22, 2010 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,49 @@ <?php /* * Author: Diego Perini * * this is what I have in my build system to embed * the packed version of NWMatcher in a PNG file; * actually any data like JSON or XML can be * transported in compressed PNG files and * avoids HTTP compression requirements. */ $filename = 'dist/nwmatcher-pac.js'; if (file_exists($filename)) { $size = filesize($filename); $width = ceil(sqrt($size / 1)); $height = $width - 1; $im = imagecreate($width, $height); $fs = fopen($filename, 'r'); $data = fread($fs, $size); fclose($fs); $i = 0; $colors = array(); for ($y = 0; $height > $y; ++$y) { for ($x = 0; $width > $x; ++$x) { if ($i < $size) { $byte = ord($data[$i]); if (!isset($colors[$byte])) { $colors[$byte] = imagecolorallocate($im, $byte, $byte, $byte); } $color = $colors[$byte]; imagesetpixel($im, $x, $y, $color); ++$i; } } } header('Content-Type: image/png'); imagepng($im, NULL, 9); imagedestroy($im); } ?>