Skip to content

Commit

Permalink
fix: add max-width (#8)
Browse files Browse the repository at this point in the history
* fix: add max-width

* Update GlideImageGenerator.php

---------

Co-authored-by: Ralph J. Smit <[email protected]>
  • Loading branch information
mansoorkhan96 and ralphjsmit authored Oct 31, 2024
1 parent 059204f commit 114710c
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions src/GlideImageGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public function src(string $path, ?int $maxWidth = null, ?string $sizes = null,
$attributes->setAttributes([
'src' => $this->getSrcAttribute($path, $maxWidth),
'srcset' => $this->getSrcsetAttribute($path, $maxWidth),
'style' => "max-width: {$this->getImageWidth($path)}px",
...$sizes !== null ? ['sizes' => $sizes] : [],
...$lazy ? ['loading' => 'lazy'] : [],
]);
Expand Down

4 comments on commit 114710c

@poldixd
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to make max-width optional?

@ralphjsmit
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@poldixd Yes, but what would be your use case?

@poldixd
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I use your package for a background image. On some very wide screens, the background image is reduced to the maximum width of the image.

At the moment I use filter() to remove the style tag.

<img 
    {{ glide()->src('img/header/AdobeStock_123456789.jpeg')->filter(fn ($value, $key) => $key !== 'style') }}
    class="absolute left-0 right-0 object-cover object-center w-full h-full"
    alt="Some alt text"
/>

@ralphjsmit
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, that makes sense, thanks! Just released 1.2.3 that adds a new parameter grow that you can use to enable images to grow past their full size by setting grow: true. Hope that helps!

Please sign in to comment.