diff --git a/BoxImage.class.php b/BoxImage.class.php index 9f5ba99..0e498aa 100644 --- a/BoxImage.class.php +++ b/BoxImage.class.php @@ -36,12 +36,27 @@ class BoxImage { * @return void * @throws Exception */ - public function __construct($size) { + public function __construct($size, $mode) { if($size < 1) throw new Exception("This cannot be done!"); //determine width+height - $this->height = ceil(sqrt($size)); - $this->width = $this->height; + switch($mode) { + case "square": + $this->height = ceil(sqrt($size)); + $this->width = $this->height; + break; + case "line": + $this->height = 1; + $this->width = $size; + break; + case "bar": + $this->height = $size; + $this->width = 1; + break; + default: + throw new Exception("Unknown mode given!"); + break; + } //prepare image for PNG with transparency using the calculated size. $this->image = imagecreatetruecolor($this->width, $this->height); @@ -98,6 +113,8 @@ class BoxImage { * @return void */ public function movePointer($offset) { + //echo $this->pointer_x.",".$this->pointer_y." --> "; + if($offset === 0) return; if($offset > 0) $step = 1; if($offset < 0){ @@ -125,14 +142,16 @@ class BoxImage { //increase x-pointer $this->pointer_x += 1; //handle y-jumps - if($this->pointer_x > $this->width) { + if($this->pointer_x >= $this->width) { $this->pointer_x = 0; $this->pointer_y += 1; //out of range? - if($this->pointer_y > $this->height) throw new Exception("Out of range! (height)"); + if($this->pointer_y >= $this->height) throw new Exception("Out of range! (height)"); } } //end of if } //end of for + + //echo $this->pointer_x.",".$this->pointer_y."\n"; } //end of function /** diff --git a/FileImageConverter.class.php b/FileImageConverter.class.php index f46b754..468fdbb 100644 --- a/FileImageConverter.class.php +++ b/FileImageConverter.class.php @@ -29,7 +29,7 @@ class FileImageConverter { * @return void * @throws Exception */ - public function convertFile($filename) { + public function convertFile($filename, $mode) { if(file_exists($filename) === FALSE) throw new Exception("Invalid filename given!"); //get file data @@ -56,9 +56,9 @@ class FileImageConverter { $size = strlen($fancy_header) + 1 + strlen($filesize) + 1 + strlen($md5) + 1 + $filesize + 1; //create and prepare image - $this->image = new BoxImage($size); + $this->image = new BoxImage($size, $mode); - echo "Image will be " . $this->image->getWidth() . "px x " . $this->image->getHeight() . "px.\n"; + echo "Image will be " . $this->image->getWidth() . "px X " . $this->image->getHeight() . "px. (Mode: " . $mode . ")\n"; echo "Filling image..."; $this->image->fillImage(0,0,0,0); @@ -92,9 +92,8 @@ class FileImageConverter { echo "Adding file contents...\n"; $this->addDataToImage($content); - //magic pixel + //magic pixel - last pixel for line and bar mode, do NOT move pointer! $this->image->setCurrentPixel(0,0,0,127); - $this->image->movePointer(1); //save image echo "Saving image..."; diff --git a/Main.php b/Main.php index 4935287..632cd50 100644 --- a/Main.php +++ b/Main.php @@ -1,11 +1,13 @@ convertFile($filename); +$converter->convertFile($filename, $mode); ?> \ No newline at end of file