From 07bdd3e26bb2db0edd1a8313608215370dc565f6 Mon Sep 17 00:00:00 2001 From: Aditya Rana Date: Thu, 11 Nov 2021 19:37:37 +0530 Subject: [PATCH 1/2] Converting negative angle values to their postive counterpart. --- app/controllers/api/storage.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/api/storage.php b/app/controllers/api/storage.php index b41983c296..01ff26f295 100644 --- a/app/controllers/api/storage.php +++ b/app/controllers/api/storage.php @@ -247,7 +247,7 @@ App::get('/v1/storage/files/:fileId/preview') ->param('borderColor', '', new HexColor(), 'Preview image border color. Use a valid HEX color, no # is needed for prefix.', true) ->param('borderRadius', 0, new Range(0, 4000), 'Preview image border radius in pixels. Pass an integer between 0 to 4000.', true) ->param('opacity', 1, new Range(0,1, Range::TYPE_FLOAT), 'Preview image opacity. Only works with images having an alpha channel (like png). Pass a number between 0 to 1.', true) - ->param('rotation', 0, new Range(0,360), 'Preview image rotation in degrees. Pass an integer between 0 and 360.', true) + ->param('rotation', 0, new Range(-360,360), 'Preview image rotation in degrees. Pass an integer between -360 and 360.', true) ->param('background', '', new HexColor(), 'Preview image background color. Only works with transparent images (png). Use a valid HEX color, no # is needed for prefix.', true) ->param('output', '', new WhiteList(\array_keys(Config::getParam('storage-outputs')), true), 'Output format type (jpeg, jpg, png, gif and webp).', true) ->inject('request') @@ -362,7 +362,7 @@ App::get('/v1/storage/files/:fileId/preview') } if (!empty($rotation)) { - $image->setRotation($rotation); + $image->setRotation(($rotation + 360) % 360); } $output = (empty($output)) ? $type : $output; From 9b64fa7f124b6af2e752e9924b32e0a87a07f82a Mon Sep 17 00:00:00 2001 From: Aditya Rana Date: Thu, 11 Nov 2021 19:41:56 +0530 Subject: [PATCH 2/2] Added test for negative angle values (-315deg equivalent to 45deg test case). --- tests/e2e/Services/Storage/StorageBase.php | 25 ++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tests/e2e/Services/Storage/StorageBase.php b/tests/e2e/Services/Storage/StorageBase.php index 395eb8ce4f..b58e235eaf 100644 --- a/tests/e2e/Services/Storage/StorageBase.php +++ b/tests/e2e/Services/Storage/StorageBase.php @@ -144,6 +144,31 @@ trait StorageBase $this->assertEquals('image/png', $file6['headers']['content-type']); $this->assertNotEmpty($file6['body']); + // Test for negative angle values in fileGetPreview + $file7 = $this->client->call(Client::METHOD_GET, '/storage/files/' . $data['fileId'] . '/preview', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'width' => 300, + 'height' => 100, + 'borderRadius' => '50', + 'opacity' => '0.5', + 'output' => 'png', + 'rotation' => '-315', + ]); + + $this->assertEquals(200, $file7['headers']['status-code']); + $this->assertEquals('image/png', $file7['headers']['content-type']); + $this->assertNotEmpty($file7['body']); + + $image = new \Imagick(); + $image->readImageBlob($file7['body']); + $original = new \Imagick(__DIR__ . '/../../../resources/logo-after.png'); + + $this->assertEquals($image->getImageWidth(), $original->getImageWidth()); + $this->assertEquals($image->getImageHeight(), $original->getImageHeight()); + $this->assertEquals('PNG', $image->getImageFormat()); + /** * Test for FAILURE */