Guest User

Untitled

a guest
Jul 18th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. diff --git a/lib/transforms/GD/sfImageCropGD.class.php b/lib/transforms/GD/sfImageCropGD.class.php
  2. index 805331d..18c80b3 100644
  3. --- a/lib/transforms/GD/sfImageCropGD.class.php
  4. +++ b/lib/transforms/GD/sfImageCropGD.class.php
  5. @@ -61,7 +61,7 @@ class sfImageCropGD extends sfImageTransformAbstract
  6. /**
  7. * Sets the left coordinate
  8. *
  9. - * @param integer
  10. + * @param integer or string (procentual representation)
  11. */
  12. public function setLeft($left)
  13. {
  14. @@ -71,6 +71,20 @@ class sfImageCropGD extends sfImageTransformAbstract
  15.  
  16. return true;
  17. }
  18. + elseif (preg_match('~[0-9]%~', $left))
  19. + {
  20. + // Limit percentage to between 0 and 100
  21. + if ((int)$left < 1)
  22. + {
  23. + $this->left = 0;
  24. + }
  25. + else
  26. + {
  27. + $this->left = min((int)$left, 100).'%';
  28. + }
  29. +
  30. + return true;
  31. + }
  32.  
  33. return false;
  34. }
  35. @@ -88,7 +102,7 @@ class sfImageCropGD extends sfImageTransformAbstract
  36. /**
  37. * set the top coordinate.
  38. *
  39. - * @param integer
  40. + * @param integer or string (procentual representation)
  41. */
  42. public function setTop($top)
  43. {
  44. @@ -98,6 +112,20 @@ class sfImageCropGD extends sfImageTransformAbstract
  45.  
  46. return true;
  47. }
  48. + elseif (preg_match('~[0-9]%~', $top))
  49. + {
  50. + // Limit percentage to between 0 and 100
  51. + if ((int)$top < 1)
  52. + {
  53. + $this->top = 0;
  54. + }
  55. + else
  56. + {
  57. + $this->top = min((int)$top, 100).'%';
  58. + }
  59. +
  60. + return true;
  61. + }
  62.  
  63. return false;
  64. }
  65. @@ -183,6 +211,16 @@ class sfImageCropGD extends sfImageTransformAbstract
  66. imagealphablending($dest_resource, false);
  67. imagesavealpha($dest_resource, true);
  68.  
  69. + // Calculate left/top if they are procentual of the image's width/height
  70. + if (strpos($this->left, '%') !== false)
  71. + {
  72. + $this->left = round((imagesx($resource) - $this->width) / (100 / $this->left));
  73. + }
  74. + if (strpos($this->top, '%') !== false)
  75. + {
  76. + $this->top = round((imagesy($resource) - $this->height) / (100 / $this->top));
  77. + }
  78. +
  79. imagecopy($dest_resource, $resource, 0, 0, $this->left, $this->top, $this->width, $this->height);
  80.  
  81. // Tidy up
Add Comment
Please, Sign In to add comment