1
0
mirror of https://github.com/e107inc/e107.git synced 2025-07-31 20:00:37 +02:00

Fixes #5387 - Avatar mime type on remote image.

This commit is contained in:
camer0n
2025-01-13 15:35:28 -08:00
parent 6aa42ccad9
commit b51833b794
2 changed files with 23 additions and 7 deletions

View File

@@ -4395,10 +4395,18 @@ class e_parse
if (!empty($options['base64'])) // embed image data into URL. if (!empty($options['base64'])) // embed image data into URL.
{ {
$content = e107::getFile()->getRemoteContent($url); // returns false during unit tests, works otherwise. $content = e107::getFile()->getRemoteContent($url);
if (!empty($content)) if (!empty($content))
{ {
$ext = strtolower(pathinfo($file, PATHINFO_EXTENSION)); if(!empty($file))
{
$ext = strtolower(pathinfo($file, PATHINFO_EXTENSION));
}
else
{
$ext = strtolower(pathinfo($url, PATHINFO_EXTENSION));
}
$url = 'data:image/' . $ext . ';base64,' . base64_encode($content); $url = 'data:image/' . $ext . ';base64,' . base64_encode($content);
} }
} }

View File

@@ -2433,16 +2433,24 @@ EXPECTED;
'alt="mytitle"', 'alt="mytitle"',
) )
), ),
/** @fixme - doesn't pass under CLI */
/*
7 => array( 7 => array(
'input' => array('user_image'=>'avatartest.png'), 'input' => array('user_image'=>'avatartest.png'),
'parms' => array('w'=>50, 'h'=>50, 'crop'=>true, 'base64'=>true, 'shape'=>'circle'), 'parms' => array('w'=>50, 'h'=>50, 'crop'=>true, 'base64'=>true, 'shape'=>'circle'),
'expected' => array( 'expected' => array(
"src='data:image/png;base64,", "src='data:image/png;base64,",
"class='img-circle user-avatar'" "class='img-circle rounded-circle user-avatar'"
) )
),*/ ),
8 => array(
'input' => array('user_image'=>'https://e107.org/e107_images/generic/blank_avatar.jpg'), // Test remote avatar
'parms' => array('w'=>50, 'h'=>50, 'crop'=>true, 'base64'=>true, 'shape'=>'circle'),
'expected' => array(
"src='data:image/jpg;base64,",
"class='img-circle rounded-circle user-avatar'"
)
),
); );
@@ -2452,7 +2460,7 @@ EXPECTED;
$result = $this->tp->toAvatar($var['input'], $var['parms']); $result = $this->tp->toAvatar($var['input'], $var['parms']);
foreach ($var['expected'] as $str) foreach ($var['expected'] as $str)
{ {
$this->assertStringContainsString($str, $result, "Failed on index #" . $index); self::assertStringContainsString($str, $result, "Failed on index #" . $index);
} }
} }