diff --git a/FileImageConverter.class.php b/FileImageConverter.class.php index 80c2431..c19443c 100644 --- a/FileImageConverter.class.php +++ b/FileImageConverter.class.php @@ -38,27 +38,39 @@ class FileImageConverter { $new_filename = "result.png"; - $header = ""; + //some gradient + $fancy_header = ""; 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 $content = file_get_contents($filename); - //get size for the image - $size = strlen($header) + 1 + $filesize; + //get final minimum size for the image + //(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 $this->image = new BoxImage($size); - $this->image->fillImage(0,0,0,127); + $this->image->fillImage(0,0,0,0); - //header first - $this->addDataToImage($header); + //some fancy 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 $this->image->setCurrentPixel(0,0,0,127); @@ -67,6 +79,10 @@ class FileImageConverter { //content $this->addDataToImage($content); + //magic pixel + $this->image->setCurrentPixel(0,0,0,127); + $this->image->movePointer(1); + //save image $this->image->writeToFile($new_filename, 0); @@ -98,7 +114,7 @@ class FileImageConverter { echo "Caught Exception:\n"; echo $e; } - echo "\rDone.\n"; + echo "\rDone. \n"; } /** diff --git a/result.png b/result.png index 7048b5a..1d487e7 100644 Binary files a/result.png and b/result.png differ diff --git a/test.jpg b/test.jpg deleted file mode 100644 index 578815a..0000000 Binary files a/test.jpg and /dev/null differ