Skip to content

Commit

Permalink
Merge pull request #23 from pboivin/fix/omit-type-if-webp-not-enabled
Browse files Browse the repository at this point in the history
Minor optimizations when webp_support is not enabled
  • Loading branch information
ptrckvzn committed Nov 6, 2021
2 parents 66e272d + 048764c commit c3e06fe
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ See [above section](#preset) about the `preset` method.
|---|---|---|---|
|`background_color`|`string`|`#e3e3e3`| |
|`lqip`|`boolean`|`true`|Uses Twill LQIP method to generate responsive placeholder|
|`webp_support`|`boolean`|`true`| |
|`webp_support`|`boolean`|`true`|If set to `false`, the `type` attribute is omitted from `<source>` elements|
|`presets`|`object`| | |

## Art directed images
Expand Down
4 changes: 3 additions & 1 deletion resources/views/picture.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
@isset($sources)
@foreach($sources as $source)
<source
type="{{ $source['type'] }}"
@if(config('twill-image.webp_support'))
type="{{ $source['type'] }}"
@endif
@if(isset($source['mediaQuery']))
media="{{ $source['mediaQuery'] }}"
@endif
Expand Down
7 changes: 4 additions & 3 deletions src/Services/MediaSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ protected function media()

public function toArray()
{
return [
return array_merge([
"alt" => $this->alt(),
"aspectRatio" => $this->aspectRatio(),
"caption" => $this->caption(),
Expand All @@ -302,10 +302,11 @@ public function toArray()
"ratio" => $this->ratio(),
"src" => $this->src(),
"srcSet" => $this->srcSet(),
"width" => $this->width(),
], (config('twill-image.webp_support') ? [
"srcWebp" => $this->srcWebp(),
"srcSetWebp" => $this->srcSetWebp(),
"width" => $this->width(),
];
] : []));
}

/**
Expand Down

0 comments on commit c3e06fe

Please sign in to comment.