diff --git a/lib/Thumbor/Url.php b/lib/Thumbor/Url.php old mode 100644 new mode 100755 index 42b5e5c..5a7c0eb --- a/lib/Thumbor/Url.php +++ b/lib/Thumbor/Url.php @@ -37,15 +37,20 @@ public function __construct($server, $secret, $original, $commands) */ public function stringify($server, $secret, $original, $commands) { - $commandPath = implode('/', $commands); - $signature = $secret ? self::sign("$commandPath/$original", $secret) : 'unsafe'; + if (count($commands) > 0) { + $commandPath = implode('/', $commands); + $imgPath = sprintf('%s/%s', $commandPath, $original); + } else { + $imgPath = $original; + } + + $signature = $secret ? self::sign($imgPath, $secret) : 'unsafe'; return sprintf( - '%s/%s/%s/%s', + '%s/%s/%s', $server, $signature, - $commandPath, - $original + $imgPath ); } diff --git a/tests/Thumbor/UrlTest.php b/tests/Thumbor/UrlTest.php old mode 100644 new mode 100755 index 556090d..1a63f7f --- a/tests/Thumbor/UrlTest.php +++ b/tests/Thumbor/UrlTest.php @@ -31,4 +31,19 @@ public function testToString() "$url" ); } + + public function testToStringWithoutCommand() + { + $url = new Url( + 'http://thumbor-server:8888', + 'MY_SECURE_KEY', + 'my/big/image.jpg', + array() + ); + + $this->assertEquals( + 'http://thumbor-server:8888/V2bYe7DAKqngbtv2GFxCcllDYWw=/my/big/image.jpg', + "$url" + ); + } }