PEAR: Image_Transform - scaleMax*() bug?

From: Date: Thu, 27 Feb 2003 18:17:38 +0000
Subject: PEAR: Image_Transform - scaleMax*() bug?
Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-14011@lists.php.net to get a copy of this message
Hello, Quoted from Image/Transform.php: /** * Scale the image to have the max x dimension specified. * * @param int $new_x Size to scale X-dimension to * @return none */ function scaleMaxX($new_x) { $new_y = round(($new_x / $this->img_x) * $this->img_y, 0); return $this->_resize($new_x, $new_y); } This function always scales the image, so i think it should be scaleByX(...) and documented like "Scale the image to have x dimension specified" (notice absence of "max"). Function scaleMaxX($max_x) should look like this: { if ($this->img_x > $max_x) { $new_y = round(($max_x / $this->img_x) * $this->img_y, 0); return $this->_resize($max_x, $new_y); } } There could also be function scaleMinX(...) similar to scaleMaxX(...), and function, that scales image if any of dimension is greater, resulting image should not be greater than $max_x, $max_y: function scaleMax($max_x, $max_y) { $factor_x = 1; $factor_y = 1; if ($this->img_x > $max_x) { $factor_x = $max_x / $this->img_x; } if ($this->img_y > $max_y) { $factor_y = $max_y / $this->img_y; } $factor = min($factor_x, $factor_y); if ($factor < 1) { return $this->scaleByFactor($factor); } } One more thing (again quoted from Tranform.php): /** * Resize the Image in the X and/or Y direction * If either is 0 it will be scaled proportionally * * @access public * * @param mixed $new_x (0, number, percentage 10% or 0.1) * @param mixed $new_y (0, number, percentage 10% or 0.1) * * @return mixed none or PEAR_error */ function resize($new_x = 0, $new_y = 0) { // 0 means keep original size $new_x = (0 == $new_x) ? $this->img_x : $this->_parse_size($new_x, $this->img_x); $new_y = (0 == $new_y) ? $this->img_y : $this->_parse_size($new_y, $this->img_y); // Now do the library specific resizing. return $this->_resize($new_x, $new_y); } It's not true that "if either is 0 it will be scaled proportionaly". If either is 0 it will be original lenght. What do you think about it? Should I code it, and send diffs? - Wojtek

« previous php.pear.dev (#14011) next »