do it
This commit is contained in:
parent
e4dca73a14
commit
871e9b9e3d
@ -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";
|
||||
}
|
||||
|
||||
/**
|
||||
|
BIN
result.png
BIN
result.png
Binary file not shown.
Before Width: | Height: | Size: 367 KiB After Width: | Height: | Size: 13 KiB |
Loading…
Reference in New Issue
Block a user