aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/vendor/splitbrain/slika/src
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/splitbrain/slika/src')
-rw-r--r--vendor/splitbrain/slika/src/Adapter.php8
-rw-r--r--vendor/splitbrain/slika/src/GdAdapter.php23
2 files changed, 27 insertions, 4 deletions
diff --git a/vendor/splitbrain/slika/src/Adapter.php b/vendor/splitbrain/slika/src/Adapter.php
index 29b9b613f..99d1de1d3 100644
--- a/vendor/splitbrain/slika/src/Adapter.php
+++ b/vendor/splitbrain/slika/src/Adapter.php
@@ -57,8 +57,8 @@ abstract class Adapter
*
* You may omit one of the dimensions to auto calculate it based on the aspect ratio
*
- * @param int $width
- * @param int $height
+ * @param int|string $width in pixels or %
+ * @param int|string $height in pixels or %
* @return Adapter
*/
abstract public function resize($width, $height);
@@ -69,8 +69,8 @@ abstract class Adapter
*
* You may omit one of the dimensions to use a square area
*
- * @param int $width
- * @param int $height
+ * @param int|string $width in pixels or %
+ * @param int|string $height in pixels or %
* @return Adapter
*/
abstract public function crop($width, $height);
diff --git a/vendor/splitbrain/slika/src/GdAdapter.php b/vendor/splitbrain/slika/src/GdAdapter.php
index 0f8db82e7..c55859955 100644
--- a/vendor/splitbrain/slika/src/GdAdapter.php
+++ b/vendor/splitbrain/slika/src/GdAdapter.php
@@ -268,6 +268,9 @@ class GdAdapter extends Adapter
*/
protected function boundingBox($width, $height)
{
+ $width = $this->cleanDimension($width, $this->width);
+ $height = $this->cleanDimension($height, $this->height);
+
if ($width == 0 && $height == 0) {
throw new Exception('You can not resize to 0x0');
}
@@ -289,6 +292,26 @@ class GdAdapter extends Adapter
}
/**
+ * Ensure the given Dimension is a proper pixel value
+ *
+ * When a percentage is given, the value is calculated based on the given original dimension
+ *
+ * @param int|string $dim New Dimension
+ * @param int $orig Original dimension
+ * @return int
+ */
+ protected function cleanDimension($dim, $orig)
+ {
+ if ($dim && substr($dim, -1) == '%') {
+ $dim = round($orig * ((float)$dim / 100));
+ } else {
+ $dim = (int)$dim;
+ }
+
+ return $dim;
+ }
+
+ /**
* Calculates crop position
*
* Given the wanted final size, this calculates which exact area needs to be cut