Results 1 to 10 of 96
Threaded View
-
9th Jan 2010, 06:20 AM #16Respected DeveloperWebsite's:
X4B.orgAlready posted go back a couple pages.
Ive tested on PHP6
PHP 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);
}
}
?>
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Similar Threads
-
Random Text & Images In Signatures
By zac2613 in forum phpBBReplies: 0Last Post: 10th Jan 2012, 06:36 AM -
How to recover deleted or lost data, file, photo on Mac with Data Recovery software
By Jack20126 in forum General DiscussionReplies: 0Last Post: 20th Dec 2011, 03:37 AM -
Random.org generated massive data
By BlaZe in forum News & Current EventsReplies: 3Last Post: 8th Jul 2011, 06:50 AM -
Random Funny Images!
By xfernanx in forum General DiscussionReplies: 1Last Post: 28th Oct 2010, 04:31 AM
themaCreator - create posts from...
Version 3.47 released. Open older version (or...