1
0
Fork 0
mirror of synced 2024-07-05 22:51:24 +12:00

Merge pull request #6164 from appwrite/fix-skip-non-ascii-chars-image

This commit is contained in:
Torsten Dittmann 2023-09-29 21:18:12 +02:00 committed by GitHub
commit 2da7cc6e69
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 4 deletions

View file

@ -525,11 +525,13 @@ App::get('/v1/avatars/initials')
$code = 0;
foreach ($words as $key => $w) {
$initials .= $w[0] ?? '';
$code += (isset($w[0])) ? \ord($w[0]) : 0;
if (ctype_alnum($w[0] ?? '')) {
$initials .= $w[0];
$code += ord($w[0]);
if ($key == 1) {
break;
if ($key == 1) {
break;
}
}
}

View file

@ -524,4 +524,28 @@ trait AvatarsBase
$this->assertEquals('PNG', $image->getImageFormat());
$this->assertEquals(strlen(\file_get_contents(__DIR__ . '/../../../resources/initials.png')), strlen($response['body']));
}
public function testSpecialCharsInitalImage()
{
$response = $this->client->call(Client::METHOD_GET, '/avatars/initials', [
'x-appwrite-project' => $this->getProject()['$id'],
], [
'name' => 'W (Hello) W',
'width' => 200,
'height' => 200,
]);
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertEquals('image/png', $response['headers']['content-type']);
$this->assertNotEmpty($response['body']);
$image = new \Imagick();
$image->readImageBlob($response['body']);
$original = new \Imagick(__DIR__ . '/../../../resources/initials.png');
$this->assertEquals($image->getImageWidth(), $original->getImageWidth());
$this->assertEquals($image->getImageHeight(), $original->getImageHeight());
$this->assertEquals('PNG', $image->getImageFormat());
$this->assertEquals(strlen(\file_get_contents(__DIR__ . '/../../../resources/initials.png')), strlen($response['body']));
}
}