This commit is contained in:
Jan Philipp Timme 2010-12-28 19:51:36 +00:00
parent e4dca73a14
commit 871e9b9e3d
3 changed files with 28 additions and 12 deletions

View File

@ -38,27 +38,39 @@ class FileImageConverter {
$new_filename = "result.png"; $new_filename = "result.png";
$header = ""; //some gradient
$fancy_header = "";
for($i = 0;$i < 255;$i += 5) { for($i = 0;$i < 255;$i += 5) {
$header .= chr($i); $fancy_header .= chr($i);
} }
$header .= chr(0);
$header .= $filesize;
$header .= chr(0);
$header .= $md5;
//header done, now read the file content //header done, now read the file content
$content = file_get_contents($filename); $content = file_get_contents($filename);
//get size for the image //get final minimum size for the image
$size = strlen($header) + 1 + $filesize; //(do not mix up strlen of $filesize and the actual $filesize)
$size = strlen($fancy_header) + 1 + strlen($filesize) + 1 + strlen($md5) + 1 + $filesize + 1;
//create and prepare image //create and prepare image
$this->image = new BoxImage($size); $this->image = new BoxImage($size);
$this->image->fillImage(0,0,0,127); $this->image->fillImage(0,0,0,0);
//header first //some fancy header
$this->addDataToImage($header); $this->addDataToImage($fancy_header);
//magic pixel
$this->image->setCurrentPixel(0,0,0,127);
$this->image->movePointer(1);
//add filesize
$this->addDataToImage($filesize);
//magic pixel
$this->image->setCurrentPixel(0,0,0,127);
$this->image->movePointer(1);
//add md5 value of content
$this->addDataToImage($md5);
//magic pixel //magic pixel
$this->image->setCurrentPixel(0,0,0,127); $this->image->setCurrentPixel(0,0,0,127);
@ -67,6 +79,10 @@ class FileImageConverter {
//content //content
$this->addDataToImage($content); $this->addDataToImage($content);
//magic pixel
$this->image->setCurrentPixel(0,0,0,127);
$this->image->movePointer(1);
//save image //save image
$this->image->writeToFile($new_filename, 0); $this->image->writeToFile($new_filename, 0);
@ -98,7 +114,7 @@ class FileImageConverter {
echo "Caught Exception:\n"; echo "Caught Exception:\n";
echo $e; echo $e;
} }
echo "\rDone.\n"; echo "\rDone. \n";
} }
/** /**

Binary file not shown.

Before

Width:  |  Height:  |  Size: 367 KiB

After

Width:  |  Height:  |  Size: 13 KiB

BIN
test.jpg

Binary file not shown.

Before

Width:  |  Height:  |  Size: 91 KiB