Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/lib/transforms/GD/sfImageCropGD.class.php b/lib/transforms/GD/sfImageCropGD.class.php
- index 805331d..18c80b3 100644
- --- a/lib/transforms/GD/sfImageCropGD.class.php
- +++ b/lib/transforms/GD/sfImageCropGD.class.php
- @@ -61,7 +61,7 @@ class sfImageCropGD extends sfImageTransformAbstract
- /**
- * Sets the left coordinate
- *
- - * @param integer
- + * @param integer or string (procentual representation)
- */
- public function setLeft($left)
- {
- @@ -71,6 +71,20 @@ class sfImageCropGD extends sfImageTransformAbstract
- return true;
- }
- + elseif (preg_match('~[0-9]%~', $left))
- + {
- + // Limit percentage to between 0 and 100
- + if ((int)$left < 1)
- + {
- + $this->left = 0;
- + }
- + else
- + {
- + $this->left = min((int)$left, 100).'%';
- + }
- +
- + return true;
- + }
- return false;
- }
- @@ -88,7 +102,7 @@ class sfImageCropGD extends sfImageTransformAbstract
- /**
- * set the top coordinate.
- *
- - * @param integer
- + * @param integer or string (procentual representation)
- */
- public function setTop($top)
- {
- @@ -98,6 +112,20 @@ class sfImageCropGD extends sfImageTransformAbstract
- return true;
- }
- + elseif (preg_match('~[0-9]%~', $top))
- + {
- + // Limit percentage to between 0 and 100
- + if ((int)$top < 1)
- + {
- + $this->top = 0;
- + }
- + else
- + {
- + $this->top = min((int)$top, 100).'%';
- + }
- +
- + return true;
- + }
- return false;
- }
- @@ -183,6 +211,16 @@ class sfImageCropGD extends sfImageTransformAbstract
- imagealphablending($dest_resource, false);
- imagesavealpha($dest_resource, true);
- + // Calculate left/top if they are procentual of the image's width/height
- + if (strpos($this->left, '%') !== false)
- + {
- + $this->left = round((imagesx($resource) - $this->width) / (100 / $this->left));
- + }
- + if (strpos($this->top, '%') !== false)
- + {
- + $this->top = round((imagesy($resource) - $this->height) / (100 / $this->top));
- + }
- +
- imagecopy($dest_resource, $resource, 0, 0, $this->left, $this->top, $this->width, $this->height);
- // Tidy up
Add Comment
Please, Sign In to add comment