Skip to content

Commit

Permalink
feat: add asset width and height as img params #3
Browse files Browse the repository at this point in the history
  • Loading branch information
simonerd committed Jun 20, 2023
1 parent 4270d6f commit c0ca254
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/Picturesque.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ public function html(): string
$output .= empty($img['alt']) ? '' : " alt='{$img['alt']}'";
$output .= empty($img['class']) ? '' : " class='{$img['class']}'";
$output .= empty($img['loading']) ? '' : " loading='{$img['loading']}'";
$output .= empty($img['width']) ? '' : " width='{$img['width']}'";
$output .= empty($img['height']) ? '' : " height='{$img['height']}'";
$output .= "/>";

$output .= '</picture>';
Expand Down Expand Up @@ -271,6 +273,16 @@ private function makeImg()
if ($this->options->get('lazy')) {
$img['loading'] = 'lazy';
}

// width
if ($w = $this->asset->width()) {
$img['width'] = $w;
}

// height
if ($h = $this->asset->height()) {
$img['height'] = $h;
}

return $img;
}
Expand Down

0 comments on commit c0ca254

Please sign in to comment.