Ok heres a better script with an actual file format. Tell me what you think HyperZ, you can make a desktop extracter if you want

Code: 
<?
    $im = new ImageContainer('file.txt','image');
    $im->CreateSplit(1024*50);//50kb split.
    /*
    Note: this is filesized splits not the output image size, the output size will depend on compression, if its text you can expect a output size of roughly 20% of the file
    else if its actually binary you can expect around 20% overhead.
    */

    $im2 = new ImageContainerExtract('image0.png');
    $im2->Extract_File('php://output');
    error_reporting(E_ALL);

    class ImageContainer {
        private $file = '';
        private $number_total = 0;
        private $out = '';

        function ImageContainer($file,$out){
            $this->file = $file;
            if(!file_exists($file)){
                throw new Exception('File does not exist');
            }
            $this->out = $out;
        }

        function CreateSplit($split){
            $fs = filesize($this->file);
            if($split>$fs){
                $split = $fs;
            }
            $this->number_total = ceil($fs/$split);//Total number of splits
            $fp = fopen($this->file,'rb');
            $i = 0;
            while($fs>0){
                $h = $w = floor(sqrt($split));
                $h += ceil((sqrt($split)-$w)/$w);
                $fs -= $h*$w;
                $this->file2image($i,$fp,$this->out.$i.'.png',$w,$h,$split);
                $i++;
            }
            fclose($fp);
        }

        function file2image($split_no,$fp,$image,$w,$h,$split){
            $header = '[I]'.dechex($split_no).'.'.dechex($this->number_total).'.'.base64_encode(basename($this->file)).'|';
            if(strlen($header)>$w*$h-$split){
                $h++;
            }

            $gd = imagecreate($w,$h);

            $color = array();
            for($i=0;$i<=255;$i++){
                $color[$i] = imagecolorallocate($gd,$i,$i,$i);
            }
            $wc = $hc =0;        

            for($hc=0;$hc<$h;$hc++){
                for($wc=0;$wc<$w;$wc++){
                    $r = '';
                    if($header) {
                        $r=$header{0};
                        $header = substr($header,1);
                    }else $r = fread($fp,1);
                    imagesetpixel($gd,$wc,$hc,$color[ord($r)]);
                }
            }
            imagepng($gd,$image,9,PNG_NO_FILTER);

            imagedestroy($gd);
        }
    }

    class ImageContainerExtract {
        private $file = '';
        private $efile = '';
        private $data = array();
        private $parts = 1;

        function ImageContainerExtract($file){
            $this->file = $file;
            $this->data[0] = $this->decode_image_raw($file);
            $part_number = $this->ReadHeader(0,true);
            if($part_number!==0){
                throw new Exception('Not first part.');
            }
            for($i=1;$i<$this->parts;$i++){
                $filen = str_replace('0.png',$i.'.png',$file);
                $this->data[$i] = $this->decode_image_raw($filen);
            }
        }

        function ReadHeader($index,$strip=true){
            $mark = substr($this->data[$index],0,3);
            switch($mark){
                case '[I]':
                    $endof = strpos($this->data[$index],'|');
                    $header = substr($this->data[$index],0,$endof);
                    if($strip){
                        $this->data[$index] = substr($this->data[$index],$endof+1);
                    }
                    list($part_number,$this->parts,$this->efile) = explode('.',$header);
                    $part_number = hexdec($part_number);
                    $this->parts = hexdec($this->parts);
                    $this->efile = base64_decode($this->efile);
                    return $part_number;
                    break;
            }
        }

        function decode_image_raw($image){
            $ret = '';
            $gd = imagecreatefrompng($image);
            list($w,$h) = getimagesize($image);
            for($ih=0;$ih<$h;$ih++){
                for($iw=0;$iw<$w;$iw++){
                    $rgb = imagecolorat($gd,$iw,$ih);
                    $ret .= chr($rgb);
                }
            }
            imagedestroy($gd);
            return $ret;
        }

        function Extract_File(){
            $fp = fopen($this->efile,'wb');
            foreach($this->data as $d){
                fwrite($fp,$d);
            }
            fclose($fp);
        }
    }
?>
FYI HyperZ to reduce all overheads ensure you use PNG8 hence only 256 combinations for colours which works nicely with the 255 different ascii characters. Also width should be equal to height (or height+1 if it isnt round) for a single file (no splits) to reduce filesize.

Anyway would be nice to hear your insight on my format, Im thinking about adding md5 and some other stuff (will add a different format specifier other than [I] to keep it backwards compatible)
SplitIce Reviewed by SplitIce on . Random idea -> Data to Images Well I'm in the process of learning a new functional programming language called F#. One of the first things people tend to do when learning a new programming language is write little, often completely useless, programs to test and verify their knowledge of the language. Same with me. Since F# is very good with processing raw data I decided to make a data to image transcoder. So the program would read data (a file) and generate an image out of that data in a way that makes it possible to Rating: 5