diff --git a/app/controllers/api/avatars.php b/app/controllers/api/avatars.php index 1059c6e1c7..fe2b53f71f 100644 --- a/app/controllers/api/avatars.php +++ b/app/controllers/api/avatars.php @@ -383,8 +383,9 @@ App::get('/v1/avatars/qr') $download = ($download === '1' || $download === 'true' || $download === 1 || $download === true); $options = new QROptions([ - 'quietzone' => $size, - 'outputType' => QRCode::OUTPUT_IMAGICK + 'addQuietzone' => true, + 'quietzoneSize' => $margin, + 'outputType' => QRCode::OUTPUT_IMAGICK, ]); $qrcode = new QRCode($options); @@ -393,10 +394,14 @@ App::get('/v1/avatars/qr') $response->addHeader('Content-Disposition', 'attachment; filename="qr.png"'); } + $resize = new Resize($qrcode->render($text)); + + $resize->crop((int) $size, (int) $size); + $response ->addHeader('Expires', \date('D, d M Y H:i:s', \time() + (60 * 60 * 24 * 45)).' GMT') // 45 days cache ->setContentType('image/png') - ->send($qrcode->render($text)) + ->send($resize->output('png', 9)) ; }); diff --git a/composer.json b/composer.json index d571e2e4fb..56f11f7405 100644 --- a/composer.json +++ b/composer.json @@ -52,7 +52,7 @@ "domnikl/statsd": "3.0.2", "influxdb/influxdb-php": "1.15.1", "phpmailer/phpmailer": "6.1.7", - "chillerlan/php-qrcode": "4.2.0" + "chillerlan/php-qrcode": "4.3.0" }, "require-dev": { "swoole/ide-helper": "4.5.5", diff --git a/composer.lock b/composer.lock index 723d6ac259..4d690a9e9e 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "025317bd1e05b735b2c4897f9cb6db4a", + "content-hash": "249dc088c5f9f74a1c0e91661f93f96b", "packages": [ { "name": "appwrite/php-clamav", @@ -57,16 +57,16 @@ }, { "name": "chillerlan/php-qrcode", - "version": "4.2.0", + "version": "4.3.0", "source": { "type": "git", "url": "https://github.com/chillerlan/php-qrcode.git", - "reference": "1972af7af51b203bc239d8fb94243f6ed2a1067a" + "reference": "4968063fb3baeedb658293f89f9673fbf2499a3e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/chillerlan/php-qrcode/zipball/1972af7af51b203bc239d8fb94243f6ed2a1067a", - "reference": "1972af7af51b203bc239d8fb94243f6ed2a1067a", + "url": "https://api.github.com/repos/chillerlan/php-qrcode/zipball/4968063fb3baeedb658293f89f9673fbf2499a3e", + "reference": "4968063fb3baeedb658293f89f9673fbf2499a3e", "shasum": "" }, "require": { @@ -119,15 +119,19 @@ ], "support": { "issues": "https://github.com/chillerlan/php-qrcode/issues", - "source": "https://github.com/chillerlan/php-qrcode/tree/4.2.0" + "source": "https://github.com/chillerlan/php-qrcode/tree/4.3.0" }, "funding": [ + { + "url": "https://www.paypal.com/donate?hosted_button_id=WLYUNAT9ZTJZ4", + "type": "custom" + }, { "url": "https://ko-fi.com/codemasher", "type": "ko_fi" } ], - "time": "2020-10-07T14:41:07+00:00" + "time": "2020-11-18T20:49:20+00:00" }, { "name": "chillerlan/php-settings-container", diff --git a/tests/e2e/Services/Avatars/AvatarsBase.php b/tests/e2e/Services/Avatars/AvatarsBase.php index e27be04e18..62722fbed3 100644 --- a/tests/e2e/Services/Avatars/AvatarsBase.php +++ b/tests/e2e/Services/Avatars/AvatarsBase.php @@ -336,6 +336,13 @@ trait AvatarsBase $this->assertEquals('image/png', $response['headers']['content-type']); $this->assertNotEmpty($response['body']); + $image = new \Imagick(); + $image->readImageBlob($response['body']); + $this->assertEquals(400, $image->getImageWidth()); + $this->assertEquals(400, $image->getImageHeight()); + $this->assertEquals('PNG', $image->getImageFormat()); + $this->assertEquals(strlen(\file_get_contents(__DIR__ . '/../../../resources/qr/qr-default.png')), strlen($response['body'])); + $response = $this->client->call(Client::METHOD_GET, '/avatars/qr', [ 'x-appwrite-project' => $this->getProject()['$id'], ], [ @@ -347,6 +354,13 @@ trait AvatarsBase $this->assertEquals('image/png', $response['headers']['content-type']); $this->assertNotEmpty($response['body']); + $image = new \Imagick(); + $image->readImageBlob($response['body']); + $this->assertEquals(200, $image->getImageWidth()); + $this->assertEquals(200, $image->getImageHeight()); + $this->assertEquals('PNG', $image->getImageFormat()); + $this->assertEquals(strlen(\file_get_contents(__DIR__ . '/../../../resources/qr/qr-size-200.png')), strlen($response['body'])); + $response = $this->client->call(Client::METHOD_GET, '/avatars/qr', [ 'x-appwrite-project' => $this->getProject()['$id'], ], [ @@ -359,6 +373,13 @@ trait AvatarsBase $this->assertEquals('image/png', $response['headers']['content-type']); $this->assertNotEmpty($response['body']); + $image = new \Imagick(); + $image->readImageBlob($response['body']); + $this->assertEquals(200, $image->getImageWidth()); + $this->assertEquals(200, $image->getImageHeight()); + $this->assertEquals('PNG', $image->getImageFormat()); + $this->assertEquals(strlen(\file_get_contents(__DIR__ . '/../../../resources/qr/qr-size-200-margin-10.png')), strlen($response['body'])); + $response = $this->client->call(Client::METHOD_GET, '/avatars/qr', [ 'x-appwrite-project' => $this->getProject()['$id'], ], [ @@ -368,6 +389,13 @@ trait AvatarsBase 'download' => 1, ]); + $image = new \Imagick(); + $image->readImageBlob($response['body']); + $this->assertEquals(200, $image->getImageWidth()); + $this->assertEquals(200, $image->getImageHeight()); + $this->assertEquals('PNG', $image->getImageFormat()); + $this->assertEquals(strlen(\file_get_contents(__DIR__ . '/../../../resources/qr/qr-size-200-margin-10.png')), strlen($response['body'])); + $this->assertEquals(200, $response['headers']['status-code']); $this->assertEquals('attachment; filename="qr.png"', $response['headers']['content-disposition']); $this->assertEquals('image/png', $response['headers']['content-type']); diff --git a/tests/e2e/Services/Users/UsersBase.php b/tests/e2e/Services/Users/UsersBase.php index 14805273e6..ebefa2abb9 100644 --- a/tests/e2e/Services/Users/UsersBase.php +++ b/tests/e2e/Services/Users/UsersBase.php @@ -125,12 +125,12 @@ trait UsersBase /** * @depends testGetUser */ - public function testUpdateUserPrefs(array $data):array + public function testUpdateAndGetUserPrefs(array $data):array { /** * Test for SUCCESS */ - $user = $this->client->call(Client::METHOD_PATCH, '/users/' . $data['userId'] . '/prefs', array_merge([ + $user = $this->client->call(Client::METHOD_PATCH, '/users/'.$data['userId'].'/prefs', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ @@ -144,6 +144,17 @@ trait UsersBase $this->assertEquals($user['body']['funcKey1'], 'funcValue1'); $this->assertEquals($user['body']['funcKey2'], 'funcValue2'); + $user = $this->client->call(Client::METHOD_GET, '/users/'.$data['userId'].'/prefs', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders())); + + $this->assertEquals($user['headers']['status-code'], 200); + $this->assertEquals($user['body'], [ + 'funcKey1' => 'funcValue1', + 'funcKey2' => 'funcValue2', + ]); + /** * Test for FAILURE */ diff --git a/tests/resources/qr/qr-default.png b/tests/resources/qr/qr-default.png new file mode 100644 index 0000000000..a7da496d9f Binary files /dev/null and b/tests/resources/qr/qr-default.png differ diff --git a/tests/resources/qr/qr-size-200-margin-10.png b/tests/resources/qr/qr-size-200-margin-10.png new file mode 100644 index 0000000000..56c59408ef Binary files /dev/null and b/tests/resources/qr/qr-size-200-margin-10.png differ diff --git a/tests/resources/qr/qr-size-200.png b/tests/resources/qr/qr-size-200.png new file mode 100644 index 0000000000..202c0cc197 Binary files /dev/null and b/tests/resources/qr/qr-size-200.png differ