Author: stunami
Date: 2010-03-10 23:12:36 +0100 (Wed, 10 Mar 2010)
New Revision: 28467
Modified:
plugins/sfImageTransformPlugin/trunk/lib/transforms/Generic/sfResizeGeneric.php
Log:
Fix to property typo
Improvements to computeTargetSize method
Modified:
plugins/sfImageTransformPlugin/trunk/lib/transforms/Generic/sfResizeGeneric.php
===================================================================
---
plugins/sfImageTransformPlugin/trunk/lib/transforms/Generic/sfResizeGeneric.php
2010-03-10 21:45:04 UTC (rev 28466)
+++
plugins/sfImageTransformPlugin/trunk/lib/transforms/Generic/sfResizeGeneric.php
2010-03-10 22:12:36 UTC (rev 28467)
@@ -23,12 +23,12 @@
/**
* width of the target
*/
- protected $width = 0;
+ protected $width = null;
/**
* height of the target
*/
- protected $height = 0;
+ protected $height = null;
/**
* do we want to inflate the source image ?
@@ -38,7 +38,7 @@
/**
* do we want to keep the aspect ratio of the source image ?
*/
- protected $proportinal = false;
+ protected $proportional = false;
/**
* constructor
@@ -173,25 +173,38 @@
*/
protected function transform(sfImage $image)
{
- $source_w = $image->getWidth();
- $source_h = $image->getHeight();
- $target_w = $this->width;
- $target_h = $this->height;
+ list($target_w, $target_h) = $this->computeTargetSize($image->getWidth(),
$image->getHeight());
+
+ return $image->resizeSimple($target_w, $target_h);
+ }
- if (is_numeric($this->width) && $this->width > 0 && $source_w > 0)
+ /**
+ * Compute target size
+ *
+ * @param integer $source_w
+ * @param integer $source_h
+ * @return array Target width and height
+ */
+ protected function computeTargetSize($source_w, $source_h)
+ {
+ $target_w = $source_w;
+ $target_h = $source_h;
+
+ if (null !== $this->width)
{
+ $target_w = $this->width;
if (!$this->inflate && $target_w > $source_w)
{
$target_w = $source_w;
}
-
- if ($this->proportional)
+
+ if ($this->proportional && $source_w > 0)
{
// Compute the new height in order to keep the aspect ratio
// and clamp it to the maximum height
$target_h = round(($source_h / $source_w) * $target_w);
-
- if (is_numeric($this->height) && $this->height < $target_h &&
$source_h > 0)
+
+ if (null !== $this->height && $this->height < $target_h && $source_h >
0)
{
$target_h = $this->height;
$target_w = round(($source_w / $source_h) * $target_h);
@@ -199,27 +212,28 @@
}
}
- if (is_numeric($this->height) && $this->height > 0 && $source_h > 0)
+ if (null !== $this->height)
{
+ $target_h = $this->height;
if (!$this->inflate && $target_h > $source_h)
{
$target_h = $source_h;
}
-
- if ($this->proportional)
+
+ if ($this->proportional && $source_h > 0)
{
// Compute the new width in order to keep the aspect ratio
// and clamp it to the maximum width
$target_w = round(($source_w / $source_h) * $target_h);
-
- if (is_numeric($this->width) && $this->width < $target_w && $source_w
> 0)
+
+ if (null !== $this->width && $this->width < $target_w && $target_w > 0)
{
$target_w = $this->width;
$target_h = round(($source_h / $source_w) * $target_w);
}
}
}
-
- return $image->resizeSimple($target_w, $target_h);
+
+ return array($target_w, $target_h);
}
}
--
You received this message because you are subscribed to the Google Groups
"symfony SVN" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/symfony-svn?hl=en.