Skip to content

Commit

Permalink
fix: image placeholder
Browse files Browse the repository at this point in the history
  • Loading branch information
ArnaudLigny committed Mar 13, 2024
1 parent a950fdc commit d6b03ea
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/Converter/Parsedown.php
Original file line number Diff line number Diff line change
Expand Up @@ -296,21 +296,26 @@ protected function inlineImage($Excerpt)
}

// placeholder
if (!empty($this->config->get('pages.body.images.placeholder')) || isset($InlineImage['element']['attributes']['placeholder'])) {
if (
(!empty($this->config->get('pages.body.images.placeholder')) || isset($InlineImage['element']['attributes']['placeholder']))
&& \in_array($InlineImage['element']['attributes']['src']['subtype'], ['image/jpeg', 'image/png', 'image/gif'])
) {
if (!\array_key_exists('placeholder', $InlineImage['element']['attributes'])) {
$InlineImage['element']['attributes']['placeholder'] = (string) $this->config->get('pages.body.images.placeholder');
}
if (!\array_key_exists('style', $InlineImage['element']['attributes'])) {
$InlineImage['element']['attributes']['style'] = '';
}
$InlineImage['element']['attributes']['style'] = trim($InlineImage['element']['attributes']['style'], ';');
switch ($InlineImage['element']['attributes']['placeholder']) {
case 'color':
$InlineImage['element']['attributes']['style'] .= sprintf(' max-width:100%%;height:auto;background-color:%s;', Image::getDominantColor($InlineImage['element']['attributes']['src']));
$InlineImage['element']['attributes']['style'] .= sprintf(';max-width:100%%;height:auto;background-color:%s;', Image::getDominantColor($InlineImage['element']['attributes']['src']));
break;
case 'lqip':
$InlineImage['element']['attributes']['style'] .= sprintf(' max-width:100%%;height:auto;background-image:url(%s);background-repeat:no-repeat;background-position:center;background-size:cover;', Image::getLqip($InlineImage['element']['attributes']['src']));
$InlineImage['element']['attributes']['style'] .= sprintf(';max-width:100%%;height:auto;background-image:url(%s);background-repeat:no-repeat;background-position:center;background-size:cover;', Image::getLqip($InlineImage['element']['attributes']['src']));
break;
}
unset($InlineImage['element']['attributes']['placeholder']);
$InlineImage['element']['attributes']['style'] = trim($InlineImage['element']['attributes']['style']);
}

Expand Down

0 comments on commit d6b03ea

Please sign in to comment.