Merge pull request #6164 from appwrite/fix-skip-non-ascii-chars-image
This commit is contained in:
commit
2da7cc6e69
|
@ -525,11 +525,13 @@ App::get('/v1/avatars/initials')
|
||||||
$code = 0;
|
$code = 0;
|
||||||
|
|
||||||
foreach ($words as $key => $w) {
|
foreach ($words as $key => $w) {
|
||||||
$initials .= $w[0] ?? '';
|
if (ctype_alnum($w[0] ?? '')) {
|
||||||
$code += (isset($w[0])) ? \ord($w[0]) : 0;
|
$initials .= $w[0];
|
||||||
|
$code += ord($w[0]);
|
||||||
|
|
||||||
if ($key == 1) {
|
if ($key == 1) {
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -524,4 +524,28 @@ trait AvatarsBase
|
||||||
$this->assertEquals('PNG', $image->getImageFormat());
|
$this->assertEquals('PNG', $image->getImageFormat());
|
||||||
$this->assertEquals(strlen(\file_get_contents(__DIR__ . '/../../../resources/initials.png')), strlen($response['body']));
|
$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']));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue