mirror of
https://github.com/e107inc/e107.git
synced 2025-01-29 10:38:08 +01:00
Fix for faulty srcset height value when using overrides and a default. Tests added.
This commit is contained in:
parent
89f58fafa6
commit
6d0fb9e218
@ -2968,12 +2968,13 @@ class e_parse extends e_parser
|
||||
/**
|
||||
* Experimental: Generate a Thumb URL for use in the img srcset attribute.
|
||||
* @param string $src eg. {e_MEDIA_IMAGE}myimage.jpg
|
||||
* @param int|str $width - desired size in px or '2x' or '3x' or null for all or array (
|
||||
* @param int|string|array $width - desired size in px or '2x' or '3x' or null for all or array (
|
||||
* @return string
|
||||
*/
|
||||
function thumbSrcSet($src='', $width=null)
|
||||
{
|
||||
$multiply = null;
|
||||
$encode = false;
|
||||
|
||||
if(is_array($width))
|
||||
{
|
||||
@ -3014,8 +3015,13 @@ class e_parse extends e_parser
|
||||
return $this->thumbUrl($src, $parm)." ".$parm['h']."h ".$multiply;
|
||||
}
|
||||
|
||||
if(isset($parm['w']) && !isset($parm['h'])) // if w set, assume h value of 0 is set.
|
||||
{
|
||||
$parm['h'] = 0;
|
||||
}
|
||||
|
||||
$width = !empty($parm['w']) ? (intval($parm['w']) * $multiply) : (intval($this->thumbWidth) * $multiply);
|
||||
$height = !empty($parm['h']) ? (intval($parm['h']) * $multiply) : (intval($this->thumbHeight) * $multiply);
|
||||
$height = isset($parm['h']) ? (intval($parm['h']) * $multiply) : (intval($this->thumbHeight) * $multiply);
|
||||
|
||||
}
|
||||
else
|
||||
|
@ -247,12 +247,9 @@ TMP;
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function testThumbSrcSet()
|
||||
{
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
public function testToDB()
|
||||
{
|
||||
|
||||
@ -787,13 +784,49 @@ TMP;
|
||||
//var_dump($result);
|
||||
}
|
||||
}
|
||||
/*
|
||||
|
||||
public function testToImage()
|
||||
{
|
||||
$src = "{e_PLUGIN}gallery/images/butterfly.jpg";
|
||||
$this->tp->setThumbSize(80,80); // set defaults.
|
||||
|
||||
// test with defaults set above.
|
||||
$result = $this->tp->toImage($src);
|
||||
$this->assertStringContainsString('butterfly.jpg&w=80&h=80', $result); // src
|
||||
$this->assertStringContainsString('butterfly.jpg&w=320&h=320', $result); // srcset 4x the size on small images.
|
||||
|
||||
// test overriding of defaults.
|
||||
$override = array('w'=>800, 'h'=>0);
|
||||
$result2 = $this->tp->toImage($src, $override);
|
||||
$this->assertStringContainsString('butterfly.jpg&w=800&h=0', $result2); // src
|
||||
$this->assertStringContainsString('Fbutterfly.jpg&w=1600&h=0', $result2); // srcset
|
||||
|
||||
|
||||
$override = array('w'=>0, 'h'=>0); // display image without resizing
|
||||
$result3 = $this->tp->toImage($src, $override);
|
||||
$this->assertStringContainsString('Fbutterfly.jpg&w=0&h=0', $result3); // src
|
||||
}
|
||||
|
||||
public function testThumbSrcSet()
|
||||
{
|
||||
$src = "{e_PLUGIN}gallery/images/butterfly.jpg";
|
||||
$parms = array('w'=>800, 'h'=>0, 'size'=>'2x');
|
||||
|
||||
$result = $this->tp->thumbSrcSet($src, $parms);
|
||||
$this->assertStringContainsString('butterfly.jpg&w=1600&h=0', $result);
|
||||
|
||||
$this->tp->setThumbSize(80,80); // set defaults.
|
||||
|
||||
$result2 = $this->tp->thumbSrcSet($src, $parms); // testing overrides
|
||||
$this->assertStringContainsString('butterfly.jpg&w=1600&h=0', $result2);
|
||||
|
||||
$result3 = $this->tp->thumbSrcSet($src, array('w'=>800, 'size'=>'2x')); // testing overrides without 'h' being set.
|
||||
$this->assertStringContainsString('butterfly.jpg&w=1600&h=0', $result3);
|
||||
|
||||
$result4 = $this->tp->thumbSrcSet($src); // no overrides
|
||||
$this->assertStringContainsString('butterfly.jpg&w=160&h=160', $result4);
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
public function testIsBBcode()
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user