Rewrite Image::getInlineImage to support double density displays

This commit is contained in:
Aaron van Geffen 2022-07-05 11:41:40 +02:00
parent 52420b8715
commit 1c02cbea93

View File

@ -67,18 +67,20 @@ class Image extends Asset
return EXIF::fromFile($this->getPath()); return EXIF::fromFile($this->getPath());
} }
public function getInlineImage($width = null, $height = null, $className = '') public function getInlineImage($width = null, $height = null, $className = 'inline-image')
{ {
if (isset($width) && isset($height)) $image_urls = [];
$image_url = $this->getThumbnailUrl($width, $height, false); if (isset($width) || isset($height))
elseif (isset($width)) {
$image_url = $this->getThumbnailUrl($width, null, false); $thumbnail = new Thumbnail($this);
elseif (isset($height)) $image_urls[1] = $this->getThumbnailUrl($width, $height, false);
$image_url = $this->getThumbnailUrl(null, $height, false); $image_urls[2] = $this->getThumbnailUrl($width * 2, $height * 2, false);
}
else else
$image_url = $this->getUrl(); $image_urls[1] = $this->getUrl();
return '<img class="inline-image ' . $className . '" src="' . $image_url . '" alt="">'; return '<img class="' . $className . '" src="' . $image_urls[1] . '" alt=""' .
(isset($image_urls[2]) ? ' srcset="' . $image_urls[2] . ' 2x"' : '') . '>';
} }
/** /**