diff --git a/CImage.php b/CImage.php index 8cb8601..e203bcb 100644 --- a/CImage.php +++ b/CImage.php @@ -147,13 +147,11 @@ class CImage { // Use newWidth and newHeigh as max width/height, image should not be larger. else { - if($this->width > $this->height) { - $factor = (float)$this->newWidth / (float)$this->width; - $this->newHeight = $factor * $this->height; - } else { - $factor = (float)$this->newHeight / (float)$this->height; - $this->newWidth = $factor * $this->width; - } + $ratioWidth = $this->width/$this->newWidth; + $ratioHeight = $this->height/$this->newHeight; + $ratio = ($ratioWidth > $ratioHeight) ? $ratioWidth : $ratioHeight; + $this->newWidth = $this->width / $ratio; + $this->newHeight = $this->height / $ratio; } } @@ -190,6 +188,8 @@ class CImage { $this->Output($this->pathToImage); } + //echo "{$this->newWidth}:{$this->newHeight}"; + // Check cache before resizing. $this->newFileName = $this->CreateFilename(); if(is_readable($this->newFileName)) { diff --git a/README.md b/README.md index 8e99c23..bc67aad 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,11 @@ Mikael Roos (mos@dbwebb.se) Revision history ---------------- +v0.1.1 (2012-04-27) + +* Corrected calculation where both width and height were set. + + v0.1 (2012-04-25) * Initial release after rewriting some older code I had lying around.