cvs: pear /Image_Transform Transform.php
| From: | Philippe Jausions | Date: | Tue, 07 Mar 2006 21:09:05 +0000 |
| Subject: | cvs: pear /Image_Transform Transform.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-38964@lists.php.net to get a copy of this message | ||
jausions Tue Mar 7 21:09:05 2006 UTC
Modified files:
/pear/Image_Transform Transform.php
Log:
Fix for Bug #6767: preventing resizing down to zero pixel width/height.
http://cvs.php.net/viewcvs.cgi/pear/Image_Transform/Transform.php?r1=1.35&r2=1.36&diff_format=u
Index: pear/Image_Transform/Transform.php
diff -u pear/Image_Transform/Transform.php:1.35 pear/Image_Transform/Transform.php:1.36
--- pear/Image_Transform/Transform.php:1.35 Tue Mar 7 20:54:08 2006
+++ pear/Image_Transform/Transform.php Tue Mar 7 21:09:05 2006
@@ -22,7 +22,7 @@
* @author Philippe Jausions <Philippe.Jausions@11abacus.com>
* @copyright 2002-2005 The PHP Group
* @license http://www.php.net/license/3_0.txt
PHP License 3.0
- * @version CVS: $Id: Transform.php,v 1.35 2006/03/07 20:54:08 jausions Exp $
+ * @version CVS: $Id: Transform.php,v 1.36 2006/03/07 21:09:05 jausions Exp $
* @link http://pear.php.net/package/Image_Transform
*/
@@ -280,8 +280,12 @@
*/
function scaleByX($new_x)
{
+ if ($new_x <= 0) {
+ return PEAR::raiseError('New size must be strictly positive',
+ IMAGE_TRANSFORM_ERROR_OUTOFBOUND);
+ }
$new_y = round(($new_x / $this->img_x) * $this->img_y, 0);
- return $this->_resize($new_x, $new_y);
+ return $this->_resize(max(1, $new_x), max(1, $new_y));
} // End scaleByX
/**
@@ -305,8 +309,12 @@
*/
function scaleByY($new_y)
{
+ if ($new_y <= 0) {
+ return PEAR::raiseError('New size must be strictly positive',
+ IMAGE_TRANSFORM_ERROR_OUTOFBOUND);
+ }
$new_x = round(($new_y / $this->img_y) * $this->img_x, 0);
- return $this->_resize($new_x, $new_y);
+ return $this->_resize(max(1, $new_x), max(1, $new_y));
} // End scaleByY
/**
@@ -355,9 +363,13 @@
*/
function scaleByFactor($size)
{
+ if ($size <= 0) {
+ return PEAR::raiseError('New size must be strictly positive',
+ IMAGE_TRANSFORM_ERROR_OUTOFBOUND);
+ }
$new_x = round($size * $this->img_x, 0);
$new_y = round($size * $this->img_y, 0);
- return $this->_resize($new_x, $new_y);
+ return $this->_resize(max(1, $new_x), max(1, $new_y));
} // End scaleByFactor
/**
@@ -371,14 +383,18 @@
*/
function scaleMaxLength($size)
{
- if ($this->img_x >= $this->img_y) {
+ if ($size <= 0) {
+ return PEAR::raiseError('New size must be strictly positive',
+ IMAGE_TRANSFORM_ERROR_OUTOFBOUND);
+ }
+ if ($this->img_x >= $this->img_y) {
$new_x = $size;
$new_y = round(($new_x / $this->img_x) * $this->img_y, 0);
} else {
$new_y = $size;
$new_x = round(($new_y / $this->img_y) * $this->img_x, 0);
}
- return $this->_resize($new_x, $new_y);
+ return $this->_resize(max(1, $new_x), max(1, $new_y));
} // End scaleMaxLength
/**